jest: [Bug]: Upgrading from 29.6.2 to 29.6.4 breaks the tests

Version

29.6.4

Steps to reproduce

Clone the following repo: https://github.com/maplibre/maplibre-gl-js run npm i run npx jest ./src/ui/map.test.ts Unit test fail

Expected behavior

The tests should not fail as this wasn’t a major version release and there should not be breaking changes.

Actual behavior

The tests started failing, this can also be observed in our PR which uses dependabot: https://github.com/maplibre/maplibre-gl-js/pull/3042

Additional context

Not sure, I tired to debug the tests and understand why they started failing, but I’m not sure what’s the root cause. Sorry that I can’t do a minimal reproduction, but I wouldn’t know where to start…

Environment

Reproduces on mac, windows, linux.

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 4
  • Comments: 24 (7 by maintainers)

Most upvoted comments

  ● Test suite failed to run

    TypeError: (0 , _jestUtil.invariant) is not a function

      at eventHandler (../node_modules/jest-circus/build/eventHandler.js:248:31)

Seemingly something in jest-circus, sorry I should have included that in my original message.

I have the same issue

Changing resetAllMocks to restoreAllMocks fixed it for me too! Thanks for the tips.

Hi guys, I got the same problem after update from 29.6.1 to 29.6.3.

In my case it was related to the resetAllMocks. I have the following script defined on setupFilesAfterEnv which works well in version 29.6.1

beforeEach(() => { jest.resetAllMocks(); });

After updating to 29.6.3 the tests stopped working. First, I took a look at my code and discovered that the tests were broken because the mock functions were not being reset, returning the same value as the previously run tests. So I took a look at the release notes and found that some changes related to mocks were reverted in the version related to this PR https://github.com/jestjs/jest/pull/14429

In trial and error I changed the script to the following code and it worked again.

beforeEach(() => { jest.restoreAllMocks(); });

@SimenB I’m studying jest under the table because I can’t explain exactly why this happened, but it solved my problem. Maybe this could be a tip on how to reproduce this problem.

Unsure if this’ll help anyone but I had an issue updating from 29.6.2 to 29.7.0 tracked it back to 29.6.3 and this change: https://github.com/jestjs/jest/pull/14366

The error was

TypeError: (0 , _jestUtil.invariant) is not a function

Forcing the resolution of jest-util to 29.7.0 and updating babel-jest to the same solved it.