[Bug]: Failed `toEqual` assertion has some sort of side-effect that causes toEqual using the same value in subsequent tests to fail incorrectly (Jest 29+ only)
MikeRippon opened this issue · 9 comments
Version
29.7.0
Steps to reproduce
- Clone repo @ https://github.com/MikeRippon/jest-luxon-bug
npm i
npm run test
Expected behavior
There should be exactly one test failure (the second test case) containing the failed expectation. The third test should pass as it is identical to the first.
Actual behavior
After the failed expectation involving the shared DateTime
, subsequent tests fail as if it has been mutated.
Additional context
Luxon is an immutable date time library, all modifications yield new objects, so it shouldn't be possible for this error to occur. I don't believe this is a fault with Luxon as the behaviour only occurs with Jest 29.0.0
and upwards.
Some observations:
- The bug is triggered by the failing expectation. Removing the expectation causes the third test to start passing.
- The bug is only triggered when comparing to another object. Substituting the object for a string or number causes the third test to start passing.
- Bug does not occur in jest 28
- Bug does occur in jest 30.0.0-alpha.3
Environment
System:
OS: Windows 11 10.0.22631
CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics
Binaries:
Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.6.3 - ~\AppData\Roaming\npm\pnpm.CMD
npmPackages:
jest: 29.7.0 => 29.7.0
Just a note so I'm not cluttering the report, I tried spending some time to re-create this without using Luxon, but it's a complex library, so without knowing anything about the internals of Jest, I can't figure out what exactly might be causing this behaviour.
For me it does not reproduce with Jest 29.0.0.
Bisecting points to #14007 as the first bad commit, which shipped with Jest 29.6.0. Very likely this is the culprit, because the issue is reproducing with Jest 29.6.0 and up.
That's odd. I just triple checked and it's definitely working for me on 28.1.3, but not 29.0.0 (I also reproduced on 29.0.0-alpha.0)
You don’t have to close. This is a bug.
While reproducing I was running the test you provided in Jest repo. All works as expected, if v29.0.0
is checked out and build. But it fails as you described from v29.6.0
and up. This is just additional info for someone interested to dig deeper.
Yes sorry, that's just me having a bad morning and clicking the wrong button!
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.