When I run in NX monorepo jest unit tests, In some tests (not in all test files) jest >= 28 throws the error:
TypeError: Cannot read properties of undefined (reading 'isFake')
150 |
151 | beforeEach(() => {
> 152 | jest.useFakeTimers();
what is an issue in the fake-timers lib on the line:
if (_global.Date.isFake === true) {
When I downgraded jest to version 27.5.1 all tests are passing. Seems like issue in initialisation of the tests.
What could be the issue ?
I was able to resolve this issue using legacy fake timers.
jest.useFakeTimers({ legacyFakeTimers: true });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With