From 0ccf5ac57ef6bd09616b55b87d9c3b9bb2e9745e Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 15 Nov 2023 16:43:02 +0100 Subject: [PATCH] docs: update msw example (#4502) --- docs/guide/mocking.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/guide/mocking.md b/docs/guide/mocking.md index e5abbc84f691..69e1c19d82d9 100644 --- a/docs/guide/mocking.md +++ b/docs/guide/mocking.md @@ -277,7 +277,7 @@ You can use it like below in your [setup file](/config/#setupfiles) ```js import { afterAll, afterEach, beforeAll } from 'vitest' import { setupServer } from 'msw/node' -import { graphql, rest } from 'msw' +import { HttpResponse, graphql, rest } from 'msw' const posts = [ { @@ -290,14 +290,18 @@ const posts = [ ] export const restHandlers = [ - rest.get('https://rest-endpoint.example/path/to/posts', (req, res, ctx) => { - return res(ctx.status(200), ctx.json(posts)) + http.get('https://rest-endpoint.example/path/to/posts', () => { + return HttpResponse.json(posts) }), ] const graphqlHandlers = [ - graphql.query('https://graphql-endpoint.example/api/v1/posts', (req, res, ctx) => { - return res(ctx.data(posts)) + graphql.query('https://graphql-endpoint.example/api/v1/posts', () => { + return HttpResponse.json( + { + data: { posts }, + }, + ) }), ]