Question: GraphQL queries are not intercepted in Jest unit test
See original GitHub issueIssue
I want to use msw
in Jest unit tests only. However, GraphQL queries are not being intercepted. Our stack is React + Jest + Apollo GraphQL.
I have already looked at https://github.com/mswjs/examples/tree/master/examples/graphql-react-apollo which is very helpful. Thanks for that.
Environment
msw: 0.19.3
nodejs: v12.14.0
npm: 6.13.4
Browser: Chrome 83.0.4103.97
I have 2 questions.
1. Do I need any extra setup to make msw
work in node (Jest unit tests)?
I believe this command is required to make msw
work in browser for development. Do I need to do something similar for node?
$ npx msw init <PUBLIC_DIR>
2. Is there any config needed for different url end point?
Our end point is /prism
instead of /graphql
. Do I need to change any config to make it work besides setting up apollo client?
Note: I have also tried changing our api url to /graphql
but it still doesn’t work.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:19 (12 by maintainers)
Top Results From Across the Web
msw: graphql operation doesn't get intercepted - Stack Overflow
Using MWS, I'm trying to mock the graphql operation testRequest ... the console.log in the graphql.query('testRequest', (_, res, ctx)=> {.
Read more >Testing React components - Apollo GraphQL Docs
This article describes best practices for testing React components that use Apollo Client. The examples below use Jest and React Testing Library, ...
Read more >Write tests with confidence - React, GraphQL and MSW
Here we intercept the GraphQL query and send custom responses based on the query variables. Here, we import graphql from msw and, we...
Read more >Testing | RedwoodJS Docs
In Redwood that's Jest, and it's known as a test runner; The amount of code you ... Redwood just intercepts the GraphQL query...
Read more >Writing Tests for Apollo Client in React - Robin Wieruch
The tutorial builds up on a mocked GraphQL API enabling you to write tests for your Apollo Client queries and mutations in React....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
MSW doesn’t currently support batched GraphQL queries. See the support progress in #513.
That’s a good comment. MSW is the replacement for
jest-fetch-mock
. Using both doesn’t guarantee any reliability and doesn’t make much sense. Thanks for highlighting that.