Replies: 1 comment 2 replies
-
Hey, @shoNagai. Your setup is correct only you're not speciying the name of the query to mock. Take a look at your GraphQL query: query ViewerQuery {
viewer {
id
name
status
}
} You seemed to have specified the field name ("viewer") when mocking, when you should've used the query name ("ViewerQuery"): // mocks/handlers.ts
import { graphql } from "msw";
export const handlers = [
// Note the change in the line below: `viewer` -> `ViewerQuery`
graphql.query(`ViewerQuery`, (req, res, ctx) => {
return res(
ctx.data({
viewer: { id: 1, name: "John Smith", status: "cached" },
})
);
}),
]; |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Environment
Request handlers
I'm using apollo client, and I'm trying to test intercepting the result of useQuery, but it's not intercepted.
The verified minimalist repository is shown below.
https://github.com/shoNagai/example-next-msw-apollo-client
When I did server.printHandlers() in jest.setup.js, the following log was output.
Beta Was this translation helpful? Give feedback.
All reactions