test(frontend): migrate MSW in Storybook to v2 (#13195)

This commit is contained in:
zyoshoka 2024-02-08 13:28:49 +09:00 committed by GitHub
parent 82c34f7f45
commit 5299d17060
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 140 additions and 143 deletions

View file

@ -286,18 +286,17 @@ export const argTypes = {
min: 1,
max: 4,
},
},
};
```
Also, you can use msw to mock API requests in the storybook. Creating a `MyComponent.stories.msw.ts` file to define the mock handlers.
```ts
import { rest } from 'msw';
import { HttpResponse, http } from 'msw';
export const handlers = [
rest.post('/api/notes/timeline', (req, res, ctx) => {
return res(
ctx.json([]),
);
http.post('/api/notes/timeline', ({ request }) => {
return HttpResponse.json([]);
}),
];
```