Skip to content

Commit

Permalink
Update docs to MSW 2.0 | rest import discontinued and replaced by htt…
Browse files Browse the repository at this point in the history
…p instead (#4607)
  • Loading branch information
Benluv authored Oct 23, 2023
1 parent 957aed6 commit 8e58a32
Show file tree
Hide file tree
Showing 5 changed files with 3,020 additions and 2,651 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"devDependencies": {
"@reduxjs/toolkit": "^1.9.0",
"@testing-library/react": "^13.4.0",
"msw": "^0.49.2",
"msw": "^2.0.0",
"react": "^18.2.0",
"react-redux": "^8.0.5"
}
Expand Down
7 changes: 4 additions & 3 deletions docs/usage/WritingTests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ export default function UserDisplay() {
}
// file: features/users/tests/UserDisplay.test.tsx
import React from 'react'
import { rest } from 'msw'
import { http, HttpResponse, delay } from 'msw'
import { setupServer } from 'msw/node'
import { fireEvent, screen } from '@testing-library/react'
// We're using our own custom render function and not RTL's render.
Expand All @@ -592,8 +592,9 @@ import UserDisplay from '../UserDisplay'
// and return the response 'John Smith' after 150ms
// when receiving a get request to the `/api/user` endpoint
export const handlers = [
rest.get('/api/user', (req, res, ctx) => {
return res(ctx.json('John Smith'), ctx.delay(150))
http.get('/api/user', async () => {
await delay(150)
return HttpResponse.json('John Smith')
})
]

Expand Down
Loading

0 comments on commit 8e58a32

Please sign in to comment.