I have this code:
//in "updateProps.jsx":
export const function update(props){ some code here };
export const function withUpdatedProps(element) {
const Wrapper = (props) => {
const updatedProps = update(props);
return <WrappedComponent {…updatedProps} />;
};
return Wrapper;
}
I want to test in unit test that function “update” was called.
import * as updateProps from ‘./updateProps’;
const TestComponent = () => <p>Hello World!</p>
TestCompnent.defaultProps = { color: "red" }
const withUpdatedProps = updateProps.withUpdatedProps;
describe("updateProps", () => {
it("does whatever", () => {
const updateSpy = jest.spyOn(updateProps, 'update');
const UpdatedTestComponent = withUpdatedProps(TestComponent);
render(<UpdatedTestComponent/>)
expect(updateSpy).toHaveBeenCalledWith(TestComponent.defaultProps);
});
});
Jest keeps saying that number of calls is ). I also tried by mocking ‘update’ and the result was the same. Can anyone help?