Show onUnhandledRequest: 'error' in stdout and fail tests
See original GitHub issueHappy new year & thanks a lot for msw
, it’s a fantastic library 🙏
Is your feature request related to a problem? Please describe.
I have an app bootstrapped with create-react-app
and various tests that I run with Jest. I would like to configure my tests to fail if msw
detects any unhandled network request. Hence, I’ve implemented the following configuration:
server.listen({ onUnhandledRequest: 'error' })
Unfortunately, doing so logs the unhandled network request errors to stderr
, which the Jest watch mode by default doesn’t show & doesn’t fail the test execution. Hence, I’ve switched back to warn
so that I can at least see if any network requests are unhandled when running the tests.
Describe the solution you’d like
- It would be great if there’s a way to direct the
error
level to stdout through the options ofserver.listen
- Likewise, maybe we could create an additional option for an event handler (e.g.
onUnhandledRequestHandler
) that one can customise to throw or runprocess.exit(1)
when we encounter an unhandled network request
Additional context
“bypass” Performs an unhandled request as-is. “warn” Prints a warning into stdout of the current process. “error” Prints an error into stderr of the current process. Source: docs
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
MSW logging warnings for unhandled Supertest requests
This could e.g. log a warning or throw an error (which will cause the test to fail). In my case, as all of...
Read more >Debugging uncaught requests - Recipes - Mock Service Worker
Whenever you are faced with a request that is not being intercepted, follow the suggestions on this page to debug the issue. Enable ......
Read more >connect econnrefused 127.0.0.1:80 - You.com | The AI Search ...
I am facing an issue where some Jest unit tests for an Angular application will not run and pass successfully in a container...
Read more >How to develop an offline Front-End app with mock data
We get some errors on the browser console saying there's no internet ... the configuration option onUnhandledRequest with the value bypass, ...
Read more >Redux Essentials, Part 8: RTK Query Advanced Patterns
The UI switches over to show <EditPostForm> , but this time there's ... has no data or there's an error, so we have...
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
Thanks a lot @kettanaito and sorry about the late reply - it’s been rather busy at work! I’ve tried out the fix you’ve published as part of #544 and it’s been working well for me 👏
I’ve opened a pull request with the suggestion above (https://github.com/mswjs/msw/pull/544). @tobiasbueschel, could you please check out that PR and use its Codesandbox preview or local build to see if it behaves as you expect now? Thanks.