Jest mocks broke updating to jest 29

Charlie Greenman
Razroo
Published in
Aug 21, 2023

How we solved

In short, we use mocks in a number of our unit tests. I personally believe jest spys are superior, however, in certain use cases we use mocks.

When we upgraded to jest 29, we found that about 50 of our 800 backend unit tests were broken for no reason. I tried a lot, but at the end of the day what I solved was adding

clearMocks: true,
resetMocks: true,
restoreMocks: true,
resetModules: true,

to our jest.config.ts file. That ended up solving unit tests. My assumption is that in later versions these were no longer the defaults and caused things to break. Thought I would share.

--

--