I'm getting some trouble about storybook-testing #32114
Replies: 1 comment 2 replies
-
Hi @Sebastien-Ahkrin! I'm Dosu and I’m helping the storybook team. This kind of test failure is usually caused by differences in how styles are applied and detected between the browser UI and the CLI/headless environment. In Storybook's own E2E and integration tests, style assertions always use getComputedStyle(element).color instead of element.style.color, because computed style reflects the actual rendered CSS, including classes and inheritance, while .style.color only checks for inline styles. This difference often causes tests to pass in Chrome but fail in the CLI or CI environments where rendering can differ slightly (example from Storybook E2E tests). Try updating your assertion like this: await waitFor(() => {
expect(getComputedStyle(textColor).color).toBe('rgb(34, 197, 94)');
}, { timeout: 3000 }); Also, make sure all userEvent actions are awaited, and use async queries like findByText or findByRole everywhere possible. This helps avoid timing issues that are more common in headless/CLI environments (discussion). If you still see discrepancies, check that all global styles, fonts, and assets are loaded identically in both environments, and consider comparing DOM snapshots or enabling debug logging to spot subtle differences (discussion). To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm trying to test if my "color" button inside my RichText is working. For that I have to test if I can click on the Button, open a classic Color Picker, pick a color then write some text. Then, my new text should be write in my specific color. The problem is that in storybook (inside chrome) everything is working good. BUT, with the CLI (and storybook) i have an error.
This is a screen inside chrome

And this inside my CLI

I have so many test like that, who's work in Chrome, but doesn't in my CLI.
I'm using this as deps :
In Additional information there is my test.
Additional information
Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions