So I have a generic class component:
import React, { Component } from "react";
export default class CompTest extends Component {
someFunc() {}
componentDidMount() {
this.someFunc();
}
render() {
return <div>Hey</div>;
}
}
and I want to check that someFunc
gets called at least once (inside componentDidMount
)
describe("<CompTest /> componendDidMount", () => {
it("should call someFun()", () => {
const wrapper = shallow(<CompTest />);
const instance = instance();
jest.spyOn(instance, "someFun");
expect(instance.someFunc).toHaveBeenCalledTimes(1);
});
});
however I am getting: Expected mock function to have been called one time, but it was called zero times.
According to enzyme v3 docs: As of Enzyme v3, the shallow API does call React lifecycle methods such as componentDidMount and componentDidUpdate.
What is wrong with my test? Thanks.
Aucun commentaire:
Enregistrer un commentaire