新的 React 脚手架创建的项目 运行报错

来源:5-4 Enzyme 的配置及使用

慕仙5575612

2020-07-20

报错代码第一张图 我test.js的代码第二张图

● Validation Error:

  Module <rootDir>/node_modules/babel-jest in the transform option was not found.
         <rootDir> is: D:\learn\tdd-react-jest

  Configuration Documentation:
  https://jestjs.io/docs/configuration.html

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tdd-react-jest@0.1.0 test: `node scripts/test.js`
npm ERR! Exit status 1
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';
import Enzyme,{ shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });

test('renders learn react link', () => {
  // const { getByText } = render(<App />);
  // const linkElement = getByText(/hello/i);
  // expect(linkElement).toBeInTheDocument();
  const wrapper = shallow(<App />)
  // expect(wrapper.find('.App')).to.have.lengthOf(1);
  console.log(wrapper.find('.App').length)
  expect(wrapper.find('.App').length).toBe(1)
});

写回答

1回答

Dell

2020-07-25

你有改动过配置项没有?

0
2
Dell
回复
慕仙5575612
我看报错提示你配置文件写的有问题,你把配置文件恢复到最初再试试。然后看下是不是配置项新版本配置的有问题。
2020-07-25
共2条回复

前端要学的测试课 从Jest入门到 TDD/BDD双实战

自动化测试实战 Vue / React 项目,让技术水平和架构思维双提升

1433 学习 · 350 问题

查看课程