Skip to content

Commit

Permalink
docs: update msw example (#4502)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Nov 15, 2023
1 parent 9b10f1c commit 0ccf5ac
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions docs/guide/mocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -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 },
},
)
}),
]

Expand Down

0 comments on commit 0ccf5ac

Please sign in to comment.