Skip to content

Commit

Permalink
🆙 update msw
Browse files Browse the repository at this point in the history
  • Loading branch information
nus3 committed Apr 16, 2024
1 parent a982f84 commit 245b1bd
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 353 deletions.
2 changes: 1 addition & 1 deletion apps/react-swc-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"jest": "28.1.0",
"jest-environment-jsdom": "28.1.0",
"jsdom": "24.0.0",
"msw": "0.44.2",
"msw": "2.2.13",
"prettier": "2.6.2",
"typescript": "5.2.2",
"vite": "5.2.8",
Expand Down
39 changes: 19 additions & 20 deletions apps/react-swc-jest/src/api/example.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import {
afterAll,
Expand All @@ -7,33 +7,32 @@ import {
test,
vi,
beforeAll,
beforeEach,
expect
} from 'vitest';

import { getExamples, GetExamplesResponse } from './example';
import { getExamples } from './example';

vi.unmock('./example');

const mockHandlers = [
http.get('/examples', () => {
return HttpResponse.json(
{
examples: [
{ id: '1', name: 'nus1' },
{ id: '2', name: 'nus2' },
{ id: '3', name: 'nus3' }
]
},
{ status: 200 }
);
})
];

const server = setupServer(...mockHandlers);

describe('/examples', () => {
const server = setupServer();
beforeAll(() => server.listen());
beforeEach(() => {
server.use(
rest.get('/examples', async (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.json<GetExamplesResponse>({
examples: [
{ id: '1', name: 'nus1' },
{ id: '2', name: 'nus2' },
{ id: '3', name: 'nus3' }
]
})
);
})
);
});
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

Expand Down
Loading

0 comments on commit 245b1bd

Please sign in to comment.