【问题标题】:Jest test Cannot read property 'Object.<anonymous>' of null开玩笑测试无法读取 null 的属性 'Object.<anonymous>'
【发布时间】:2018-05-02 10:06:40
【问题描述】:
/Users/***/Desktop/projects/***/node_modules/jest-runtime/build/index.js:517
    const wrapper = this._environment.runScript(transformedFile.script)[

有时如果我运行 npm test jest 给出这个错误。

【问题讨论】:

标签: reactjs react-native testing jestjs


【解决方案1】:

这可能是由在 React Native 中运行动画动画引起的。检测到笑话时不运行该动画是我目前找到的最佳解决方案。我试着不运行动画,错误消失了。

【讨论】:

    【解决方案2】:

    当我在测试中不浅渲染组件时会发生这种情况。

    我的猜测是子组件的渲染引起的,所以我模拟了渲染函数的父组件,测试开始运行良好。

    你有一个很好的模拟子组件的例子:https://jestjs.io/docs/en/es6-class-mocks

    【讨论】:

      猜你喜欢
      • 2020-06-15
      • 2020-07-10
      • 2017-07-24
      • 2020-06-26
      • 2023-03-03
      • 2019-01-28
      • 2022-01-18
      • 2019-02-16
      • 2019-10-09
      相关资源
      最近更新 更多