Im my react component, I have props like below
interface Props {
errorMessage: JSX.Element;
addCommentCancel: () => void;
triggerAddComment: () => void;
showAddCommentForm: boolean;
}
and in the test I'm invoking the component like below
const props = {
errorMessage: {},
addCommentCancel: () => jest.fn(),
triggerAddComment: () => jest.fn(),
showAddCommentForm: true
};
let wrapper = mount(<IncidentCommentList {...props} />);
I get an error
Type '{}' is not assignable to type 'Element'.
How do I mock props element?
JSX.Element
either stands for JSX element(e.g.<span />
) or is a string. Maybenull
also works but I'm not sure. Did not findJSX.Element
declaration in React or DefinitelyTypes so not filling "official answer" – skyboyer