[0.19.5] Docs and example now error regarding use of setupWorker in Node
See original GitHub issueDescribe the bug
Not really a bug, just a discrepancy between the documentation/example and the behavior in the latest release. #219 throws an error when you try to use setupWorker
in Node (e.g. Jest tests), but the documentation and the rest-react
example both call it directly in the mocks file, so you can’t use that same file in the browser and Node-based tests.
Environment
msw: 0.19.5
nodejs: 12.18.1
npm: 6.14.5
Browser: N/A
To Reproduce
Steps to reproduce the behavior:
- Setup
rest-react
example - Run
npm run test:unit
- See error:
[MSW] Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for NodeJS environment instead.
Expected behavior
I expected the example to work and the steps in the documentation to produce a working structure.
Possible solutions
Is it just a matter of restructuring the docs/example to match the graphql-react-apollo
example where the handlers are separate from the setupWorker
/setupServer
calls?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Worker threads | Node.js v19.3.0 Documentation
The node:worker_threads module enables the use of threads that execute JavaScript in parallel. To access it: const worker = require('node:worker_threads');.
Read more >setupServer() - Api - Mock Service Worker Docs
This function is designed for NodeJS environment. If looking for a way to apply API mocking in a browser environment, consider using setupWorker...
Read more >msw: Versions - Openbase
The worker script ( mockServiceWorker.js ) now contains the library version number to improve its inspection and debugging across releases (#781). Bug fixes....
Read more >Configuring Mock Service Worker (MSW) - Daniel Afonso blog
Mock Service Worker is an API mocking library that uses Service Worker API to intercept actual requests. MSW docs. In a short description, ......
Read more >Getting started with Mock Service Worker - LogRocket Blog
What is Mock Service Worker, and what problem does it solve? ... Let's add Mock Service Work to our application now. We can...
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
I’ve updated the “Getting stared” tutorial to recommend the proper file structure. Thanks once more for bringing this up.
That’s definitely a valid concern. I’ve opened an issue in the docs about that: https://github.com/mswjs/mswjs.io/issues/9