Skip to content

Commit 8e58a32

Browse files
authored
Update docs to MSW 2.0 | rest import discontinued and replaced by http instead (#4607)
1 parent 957aed6 commit 8e58a32

File tree

5 files changed

+3020
-2651
lines changed

5 files changed

+3020
-2651
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"devDependencies": {
44
"@reduxjs/toolkit": "^1.9.0",
55
"@testing-library/react": "^13.4.0",
6-
"msw": "^0.49.2",
6+
"msw": "^2.0.0",
77
"react": "^18.2.0",
88
"react-redux": "^8.0.5"
99
}

docs/usage/WritingTests.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ export default function UserDisplay() {
581581
}
582582
// file: features/users/tests/UserDisplay.test.tsx
583583
import React from 'react'
584-
import { rest } from 'msw'
584+
import { http, HttpResponse, delay } from 'msw'
585585
import { setupServer } from 'msw/node'
586586
import { fireEvent, screen } from '@testing-library/react'
587587
// We're using our own custom render function and not RTL's render.
@@ -592,8 +592,9 @@ import UserDisplay from '../UserDisplay'
592592
// and return the response 'John Smith' after 150ms
593593
// when receiving a get request to the `/api/user` endpoint
594594
export const handlers = [
595-
rest.get('/api/user', (req, res, ctx) => {
596-
return res(ctx.json('John Smith'), ctx.delay(150))
595+
http.get('/api/user', async () => {
596+
await delay(150)
597+
return HttpResponse.json('John Smith')
597598
})
598599
]
599600

0 commit comments

Comments
 (0)