I'm trying to add some tests to my application, but when I installed react-testing-library
and jest-dom
, I wrote this test, test if componentDidMount
is called:
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);
});
But I get this error:
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'].
I don't think that the file extension is problem..
Aucun commentaire:
Enregistrer un commentaire