question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Show onUnhandledRequest: 'error' in stdout and fail tests

See original GitHub issue

Happy 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

  1. It would be great if there’s a way to direct the error level to stdout through the options of server.listen
  2. Likewise, maybe we could create an additional option for an event handler (e.g. onUnhandledRequestHandler) that one can customise to throw or run process.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:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tobiasbueschelcommented, Mar 3, 2021

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 👏

0reactions
kettanaitocommented, Jan 18, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found