【问题标题】:TypeError: Cannot read property 'type' of undefined Jest react testing [closed]TypeError:无法读取未定义 Jest 反应测试的属性“类型”[关闭]
【发布时间】:2022-02-11 19:43:28
【问题描述】:

我正在使用 jest 和酵素来测试使用 Material UI 库编写的应用程序组件。然后在我的一个包裹中,我收到了这个错误 Click here to see the error

【问题讨论】:

    标签: javascript jestjs enzyme material-ui-x


    【解决方案1】:

    我通过以下步骤解决了上述问题

    1.创建一个文件夹并在 setupFilesAfterEnv.js 中添加以下代码

    jest.mock('@material-ui/core/styles/colorManipulator', () => ({
    
      fade: jest.fn(),
    
    }));
    

    2.在你的包文件夹中的 jest.config.js 中导入上述文件的路径

     setupFilesAfterEnv: [require.resolve('../../test/setupEnzymeAdapter.js'),
    <rootDir>../tests/setupFilesAfterEnv.js
    

    我的问题已经解决了。

    【讨论】:

      猜你喜欢
      • 2021-09-20
      • 1970-01-01
      • 2021-05-17
      • 2019-05-05
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      • 2021-11-07
      • 2018-11-27
      相关资源
      最近更新 更多