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 ?
2条答案
按热度按时间hrirmatl1#
我能够解决这个问题使用传统的假计时器。
w7t8yxp52#
在我的例子中,我只是通过使用
fakeTimers
Jest配置解决了这个问题,如下所示:然后我从我的规格中删除了单个的
jest.useFakeTimers();
。这就消除了TypeError: Cannot read property 'isFake' of undefined
错误。参考:https://jestjs.io/docs/28.x/upgrading-to-jest28#fake-timers