mer*_*rko 5 javascript testing reactjs react-testing-library
我正在尝试向我的应用程序添加一些测试,但是当我安装react-testing-libraryand 时jest-dom,我编写了这个测试, test ifcomponentDidMount被调用:
import { render } from "react-testing-library";
import { QuestionContainer } from "../containers/QuestionContainer";
it("should call componentDidMount", () => {
const cDM = jest.spyOn(QuestionContainer.prototype, "componentDidMount");
render(QuestionContainer);
expect(cDM).toHaveBeenCalled(1);
});
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
Cannot find module 'react' from 'index.js'
However, Jest was able to find:
'../containers/QuestionContainer.js'
You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].
Run Code Online (Sandbox Code Playgroud)
我不认为文件扩展名有问题..
| 归档时间: |
|
| 查看次数: |
4935 次 |
| 最近记录: |