mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 03:11:49 +08:00
27 lines
781 B
Plaintext
27 lines
781 B
Plaintext
```js
|
|
// MyForm.stories.js
|
|
import { expect, userEvent, within } from '@storybook/test';
|
|
import { cookies, headers } from '@storybook/nextjs/headers.mock';
|
|
|
|
import MyForm from './my-form';
|
|
|
|
export default {
|
|
component: MyForm,
|
|
};
|
|
|
|
export const LoggedInEurope = {
|
|
async beforeEach() {
|
|
// 👇 Set mock cookies and headers ahead of rendering
|
|
cookies().set('username', 'Sol');
|
|
headers().set('timezone', 'Central European Summer Time');
|
|
},
|
|
async play() {
|
|
// 👇 Assert that your component called the mocks
|
|
await expect(cookies().get).toHaveBeenCalledOnce();
|
|
await expect(cookies().get).toHaveBeenCalledWith('username');
|
|
await expect(headers().get).toHaveBeenCalledOnce();
|
|
await expect(cookies().get).toHaveBeenCalledWith('timezone');
|
|
},
|
|
};
|
|
```
|