Jest无法正常运行Create-React-App“无法从componentY找到模块nodeModuleX”

时间:2018-11-20 05:57:17

标签: reactjs jestjs enzyme

我正试图开始测试我的项目中的组件,这些项目是通过带有Jest的Create React App创建的。我为一个组件创建了一个简单的测试文件,并且从与我要测试的组件甚至不相关的组件中获取“错误”。我正在使用Create React App,所以我无法更改Jest的配置。

那是测试文件

/** Home.test.js */

import React from 'react';
import ReactDOM from 'react-dom';
import Home from '../../components/Home';

test('renders without crashing', () => {
    const div = document.createElement('div');
    ReactDOM.render(<Home />, div);
 });

那是错误

FAIL  src\__tests__\components\Home.test.js
  ● Test suite failed to run

    Cannot find module 'signature_pad' from 'Signature.jsx'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (src/components/common/inputs/Signature.jsx:3:22)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.031s
Ran all test suites related to changed files.

如果我在组件Signature.jsx上注释了代码的导入行,则会从另一个组件收到另一个错误:

src\__tests__\components\Home.test.js
  ● Test suite failed to run

    TypeError: _WorkerDriverLicenceSchema2.default is not iterable

      at Object.<anonymous> (src/components/profiles/worker/forms/WorkerDriverLicences.jsx:35:33)
      at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerViewDetails.jsx:18:29)
      at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerDetailsModal.jsx:7:26)
      at Object.<anonymous> (src/components/common/uiElements/UserDetailsLink.jsx:7:27)
      at Object.<anonymous> (src/components/common/uiElements/index.js:13:247)
      at Object.<anonymous> (src/components/common/layout/ChangeLog.jsx:5:19)
      at Object.<anonymous> (src/components/common/layout/index.js:1:182)
      at Object.<anonymous> (src/components/Home.jsx:4:15)
      at Object.<anonymous> (src/__tests__/components/Home.test.js:5:13)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:189:7)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.18s
Ran all test suites related to changed files.

0 个答案:

没有答案