I have a function, that returns JSX Element.
myFunction.jsx
const myFunction = (props) => {
// ... do something with props
return <MyElement {...newProps} />
}
// MyElement.jsx
export const MyElement = (props) => {
// ... return some jsx
}
My goal is to check that myFunction returns an element with correct set of props. But I don't want to include render of MyComponent to test, so I mocked it. I tried to test it like this:
const mockFn = jest.fn();
jest.mock('.../path-to-my-component/MyComponent, () => ({
MyComponent: (props) => {
mockFn(props)
return 'my-component'
}
}))
// ....
myFunction(someProps)
expect(mockFn).toHaveBeenCalled() // mockFn have been called 0 times
expect(mockFn).toHaveBeenCalledWith(someProps)
But both expects were failed.