Skip to content

Commit

Permalink
Update WritingTests.mdx | rest import discontinued and replaced by ht…
Browse files Browse the repository at this point in the history
…tp instead

- In msw docs they seem to be using http and HttpResponse for requests https://mswjs.io/docs/api/setup-server/
- Delay is performed with await so the function is now async https://mswjs.io/docs/api/delay/
  • Loading branch information
Benluv authored Oct 23, 2023
1 parent 957aed6 commit cd1568f
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit cd1568f

Please sign in to comment.