I am doing test on the React+Typescript using React Testing Library and Jest. This test could not run at all with the following error:
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason “TypeError: Cannot read properties of undefined (reading ‘json’)”.] {
code: ‘ERR_UNHANDLED_REJECTION’
}
Here is my test. Please help my to fix it.
const renderComponent = (): RenderResult => {
return render(
<List />,
{}
);
};
const { getByTestId, findByTestId, findByText } = screen;
const renderElements = (): any => {
const component = renderComponent();
return {
deleteIcon: screen.getByTestId("delete-icon"),
dialogPopup: screen.getByTestId("dialog-popup"),
component,
};
};
describe("When click on Delete icon", () => {
it("should show Dialog Confirmation Popup", () => {
const { deleteIcon, dialogPopup } = renderElements();
userEvent.click(deleteIcon);
expect(dialogPopup).toBeInTheDocument();
});
});