I have a props with JSX.Element. How do I mock the same in the jest test

Viewed 792

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?

1 Answers
const props =  {
  errorMessage: <div>errorMessage</div>,
  addCommentCancel: () => jest.fn(),
  triggerAddComment: () => jest.fn(),
  showAddCommentForm: true
};
let wrapper = mount(<IncidentCommentList {...props} />);

The above code fixed the issue.

Related