-
SummaryHi, at my company we're using chromatic to make non regression visual testing but we are confronted with a problematic we don't know how to fix it. We have certain components that use We don't want to pollute our components with an environment detection based solely on storybook / chromatic, and neither want to use We have same problematics on components using a So my question is: Thanks. Additional informationNo response Create a reproductionNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
Hi @Yimiprod! I'm Dosu and I’m helping the storybook team. There isn’t a built-in Storybook or Chromatic feature to globally pause or mock setInterval/setTimeout just for Chromatic snapshots. However, you can use environment detection in your Storybook config to override these timer functions only during Chromatic runs, without touching your component code. Storybook provides an isChromatic utility that detects when your stories are running in Chromatic by checking the user agent or URL parameters. You can use this in your .storybook/preview.js (or .ts) to override setInterval and setTimeout globally during Chromatic runs. For example: // .storybook/preview.js
import { isChromatic } from './isChromatic';
if (isChromatic()) {
// Pause all intervals and timeouts during Chromatic snapshotting
window.setInterval = () => 0;
window.setTimeout = () => 0;
window.clearInterval = () => {};
window.clearTimeout = () => {};
}This will effectively freeze any JS-based timers while Chromatic is taking snapshots, making your visual tests deterministic and avoiding unwanted diffs. You can adjust the stubs if you want to allow some timers to run or log their usage for debugging. Keep in mind: this approach will affect all stories during Chromatic runs, so if you have stories that rely on timers for their initial render, you may need to fine-tune the logic or use a more targeted override. Other approaches like disabling CSS animations or using Chromatic parameters (e.g., Test this in your Chromatic environment to confirm it works as expected. If you need more granular control, you can wrap the override in a decorator or only apply it to specific stories. Reference: isChromatic utility implementation | Usage in preview config To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Still making Chromatic throw error, chromatic usin setInterval behind the scene to handle some waiting time, here's a possible solution:
Warning
if the component use an interval less than 1 second, it will not use the mocked version