Commit b89c6e3
fix(design-system): use mockdate in storybook tests instead of vi [AR-46279] (#124)
## Steps to reporoduce
Navigate to [Storybook DateInput
component](https://drivenets.github.io/design-system/?path=/docs/design-system-dateinput--docs).
You'll see error:
<img width="1554" height="734" alt="image"
src="https://github.com/user-attachments/assets/2f5e5b47-bc26-4783-a5fd-bb924a974fa8"
/>
## Root cause
In a nutshell, importing from vitest `import { vi } from 'vitest';`
breaks storybook. See details
[here](storybookjs/storybook#31400 (comment)).
## Solution
Use [mockdate](https://www.npmjs.com/package/mockdate) package to mock
dates. I took the idea from [Storybook
documentation](https://storybook.js.org/docs/writing-stories/mocking-data-and-modules/mocking-modules#setting-up-and-cleaning-up).
### Alternative Solution
I also considered
[@sinonjs/fake-timers](https://www.npmjs.com/package/@sinonjs/fake-timers)
package since it is more popular and in active development, but it's
usage looks a bit more complicated and its size is 103 kB versus 13.8 kB
of [mockdate](https://www.npmjs.com/package/mockdate)
---------
Co-authored-by: Evyatar Daud <32631382+StyleShit@users.noreply.github.com>1 parent 3524248 commit b89c6e3
3 files changed
Lines changed: 17 additions & 16 deletions
File tree
- packages/design-system
- src/components/ds-date-input
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
Lines changed: 5 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
25 | 23 | | |
26 | 24 | | |
27 | | - | |
| 25 | + | |
28 | 26 | | |
29 | 27 | | |
30 | 28 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments