【问题标题】:Jest throws TypeError: Cannot read properties of undefined (reading 'isFake')Jest 抛出 TypeError: Cannot read properties of undefined (reading \'isFake\')
【发布时间】:2022-10-06 20:30:27
【问题描述】:

当我在 NX monorepo jest 单元测试中运行时,在某些测试中(不是在所有测试文件中) jest >= 28 会引发错误:

TypeError: Cannot read properties of undefined (reading \'isFake\')

  150 |
  151 |   beforeEach(() => {
> 152 |     jest.useFakeTimers();

在线的假计时器库中有什么问题: if (_global.Date.isFake === true) {

当我将 jest 降级到 27.5.1 版本时,所有测试都通过了。似乎是测试初始化​​的问题。

可能是什么问题 ?

    标签: angular jestjs nrwl


    【解决方案1】:

    我能够使用旧版假计时器解决此问题。

    jest.useFakeTimers({ legacyFakeTimers: true });
    

    【讨论】:

      猜你喜欢
      • 2021-11-10
      • 2021-11-03
      • 2021-11-08
      • 2022-11-11
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 2022-07-09
      • 2022-01-11
      相关资源
      最近更新 更多