I have written a story with Storybook UI and deploying it with Chromatic. The issue is that my component takes into account the time now (I am using luxon, so I am using DateTime.now()
, and it takes the diff with another date passed by props to show how many minutes have passed. Now, I am passing a fixed date to compare with, but the diff between now and that date makes it so that everytime code is pushed to Chromatic, it sees that as a change. How can I "freeze" DateTime.now()
in Storybook so that this problem doesn't happen?
Asked
Active
Viewed 437 times
3

davidaap
- 1,569
- 1
- 18
- 43
1 Answers
1
I just patch my Date.now
function within the individual Story. You might want to patch other function depending upon how you're grabbing the date.
Date.now = () => new Date("2022-06-13T12:33:37.000Z");

Alfonso Embid-Desmet
- 3,561
- 3
- 32
- 45
-
Thanks for posting your solution, but where did you set this, inside the story decorator or something? – CodeNameGrant Aug 02 '23 at 14:09