Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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) #15046

Open
MikeRippon opened this issue May 1, 2024 · 6 comments

Comments

@MikeRippon
Copy link

Version

29.7.0

Steps to reproduce

  1. Clone repo @ https://github.com/MikeRippon/jest-luxon-bug
  2. npm i
  3. 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
@MikeRippon
Copy link
Author

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.

@MikeRippon MikeRippon changed the title [Bug]: Failed toEqual assertion has some sort of side-effect that causes toEqual using the same value in subsequent tests to fail (Jest >= 29 only) [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) May 1, 2024
@MikeRippon MikeRippon changed the title [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) [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) May 1, 2024
@mrazauskas
Copy link
Contributor

mrazauskas commented May 2, 2024

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.

@MikeRippon
Copy link
Author

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)

@mrazauskas
Copy link
Contributor

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.

@MikeRippon MikeRippon reopened this May 2, 2024
@MikeRippon
Copy link
Author

Yes sorry, that's just me having a bad morning and clicking the wrong button!

Copy link

github-actions bot commented Jun 1, 2024

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.

@github-actions github-actions bot added the Stale label Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants