reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.74k stars 1.18k forks source link

Sad path throws jest error which fails the test using MSW #3620

Closed DominicGBauer closed 1 year ago

DominicGBauer commented 1 year ago

Description When testing sad path for mutations and lazy queries, unless I use an empty catch statement at the end of the the promise my tests fail when using msw to return a 400/500 error.

I have also raised this issue in MSW and they said it was not an issue on their side https://github.com/mswjs/msw/issues/1661

Reproduction repository https://github.com/DominicGBauer/msw-test-example

Reproduction steps Run yarn test The sad path tests will fail Go to Example.tsx and uncomment the function with try catch and comment the function without try catch. Run yarn test The tests pass

Current behavior I get this error at the end of the tests when I do not catch an error using an RTK API mutation or lazy query

thrown: Object {
  "data": null,
  "status": 500,
}

  at _getError (../../node_modules/jest-circus/build/utils.js:431:18)
      at Array.map (<anonymous>)

Expected behavior Jest shouldn't be throwing an error

phryneas commented 1 year ago

.unwrap() means that you get the value, but have to catch errors. This is a deliberate choice you make in your code.

DominicGBauer commented 1 year ago

Oh shucks sorry thanks!