Skip to content

Using "onUnhandledRequest": "error" does not fail tests #946

@bennettdams

Description

@bennettdams

Describe the bug

When a server ist configured to listen with onUnhandledRequest: "error", the test where this error occurs does not fail.

image

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:

  1. Install initial Create Next App with TypeScript
    npx create-next-app@latest --use-npm --ts .
    bennettdams/msw-nextjs-bug@2cf426a

  2. Create src folder at root and move pages folder to it
    bennettdams/msw-nextjs-bug@78b657e

  3. 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

  4. Create a simple test file based on Next's docs:
    bennettdams/msw-nextjs-bug@bd9ba77

  5. Install MSW and follow setup for mocks/handlers/server via docs:
    npm install msw --save-dev
    bennettdams/msw-nextjs-bug@cdd07c1

  6. Integrate MSW with Jest
    bennettdams/msw-nextjs-bug@3973836

  7. Install and utilize whatwg-fetch - needed for Polyfill with Next.js
    npm install -D whatwg-fetch
    bennettdams/msw-nextjs-bug@5cbe84a

  8. 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.

Metadata

Metadata

Assignees

Labels

DXbugSomething isn't workinghelp wantedExtra attention is neededneeds:discussionscope:browserRelated to MSW running in a browserscope:nodeRelated to MSW running in Node

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions