From cd1568f31f0328ecdc3af15fe7e2912edee627f8 Mon Sep 17 00:00:00 2001 From: Benito Luongo Date: Mon, 23 Oct 2023 14:36:42 +0200 Subject: [PATCH] Update WritingTests.mdx | rest import discontinued and replaced by http 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/ --- docs/usage/WritingTests.mdx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/usage/WritingTests.mdx b/docs/usage/WritingTests.mdx index 848f5d59a8..409980b3c2 100644 --- a/docs/usage/WritingTests.mdx +++ b/docs/usage/WritingTests.mdx @@ -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. @@ -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') }) ]