storybook/docs/snippets/common/before-each-in-meta-mock-date.js.mdx

27 lines
519 B
Plaintext

```js
// Page.stories.js
import MockDate from 'mockdate';
import { getUserFromSession } from '#api/session.mock';
import { Page } from './Page';
export default {
component: Page,
// 👇 Set the value of Date for every story in the file
async beforeEach() {
MockDate.set('2024-02-14');
// 👇 Reset the Date after each story
return () => {
MockDate.reset();
};
},
};
export const Default = {
async play({ canvasElement }) {
// ... This will run with the mocked Date
},
};
```