Reactjs 带有React的Jest测试库

Reactjs 带有React的Jest测试库,reactjs,unit-testing,react-router,jestjs,enzyme,Reactjs,Unit Testing,React Router,Jestjs,Enzyme,嗨,我是使用create-react-app方法创建的react-app,没有在外部安装jest,因为create-react-app有内置jest库。 我的问题是,当我尝试运行代码时,会出现以下错误: Cannot find module 'react' from 'react-router.js' However, Jest was able to find: './Menu.js' at Resolver.resolveModule (node_modules/jest-resolve/b

嗨,我是使用create-react-app方法创建的react-app,没有在外部安装jest,因为create-react-app有内置jest库。 我的问题是,当我尝试运行代码时,会出现以下错误:

Cannot find module 'react' from 'react-router.js'
However, Jest was able to find:
'./Menu.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
at Object.<anonymous> (../node_modules/react-router/cjs/react-router.js:5:29)
无法从“react router.js”中找到模块“react”
然而,Jest发现:
“./Menu.js”
在Resolver.resolveModule(node_modules/jest resolve/build/index.js:259:17)
反对。(../node_modules/react router/cjs/react router.js:5:29)
这是我的密码:

import React from 'react';
import { shallow } from 'enzyme';
import ApplyLoan from './Components/applyloan.js';

    describe('Test Button component', () => {
      it('Test click event', () => {
        const mockCallBack = jest.fn();
    
        const button = shallow((<ApplyLoan onClick={mockCallBack}>Ok!</ApplyLoan>));
        button.find('applyloansubmit').simulate('click');
        expect(mockCallBack.mock.calls.length).toEqual(1);
      });
    });
从“React”导入React;
从“酶”导入{shall};
从“/Components/ApplyLoan.js”导入ApplyLoan;
描述('测试按钮组件',()=>{
它('测试点击事件',()=>{
const mockCallBack=jest.fn();
常量按钮=浅((好!));
按钮。查找('applyloansubmit')。模拟('click');
expect(mockCallBack.mock.calls.length).toEqual(1);
});
});

您好,我的问题不是关于jest安装。我不是安装在外部的笑话。这是关于我上面提到的错误