-
-
Notifications
You must be signed in to change notification settings - Fork 562
Description
Describe the bug
When a server ist configured to listen with onUnhandledRequest: "error"
, the test where this error occurs does not fail.
Based on this discussion: #943
Environment
- Next.js, Jest, React Testing Library & MSW
https://github.com/bennettdams/msw-nextjs-bug/blob/master/package.json
This happens for a fresh install with all default configuration from the Next.js & MSW docs.
msw: 0.35.0
nodejs: 14.18.0
npm: 6.14.15
To Reproduce
Reproduction repo: https://github.com/bennettdams/msw-nextjs-bug
To try it out:
npm i
npm run test
Steps to reproduce the behavior from zero:
-
Install initial Create Next App with TypeScript
npx create-next-app@latest --use-npm --ts .
bennettdams/msw-nextjs-bug@2cf426a -
Create
src
folder at root and movepages
folder to it
bennettdams/msw-nextjs-bug@78b657e -
Install & configure Jest, testing libs, etc. based on Next's docs:
npm install --save-dev jest babel-jest @testing-library/react @testing-library/jest-dom identity-obj-proxy react-test-renderer
bennettdams/msw-nextjs-bug@aaf1fb3 -
Create a simple test file based on Next's docs:
bennettdams/msw-nextjs-bug@bd9ba77 -
Install MSW and follow setup for mocks/handlers/server via docs:
npm install msw --save-dev
bennettdams/msw-nextjs-bug@cdd07c1 -
Integrate MSW with Jest
bennettdams/msw-nextjs-bug@3973836 -
Install and utilize
whatwg-fetch
- needed for Polyfill with Next.js
npm install -D whatwg-fetch
bennettdams/msw-nextjs-bug@5cbe84a -
Change server config to
onUnhandledRequest: "error"
and add some simple fetch execution in the tested component
bennettdams/msw-nextjs-bug@f77bb0f
==> The test does not fail, even though the tests shows the error.
Expected behavior
When onUnhandledRequest
is configured with error
and an unhandled request is found, the test shoud fail.