This is how my test case looks :
const renderCard = ({
onSubmit = jest.fn(),
}: RenderCardParams = {}) => {
return render(
<Card title={title} onSubmit={onSubmit}>
<Button type="submit">Save</Button>
</Card>,
);
};
it("should invoke onSubmit when form is submitted", async () => {
const onSubmit = jest.fn();
window.HTMLFormElement.prototype.submit = () => {};
const { getByText } = renderCard({ onSubmit });
const button = getByText("Save").closest("button");
if (button) {
fireEvent.click(button);
}
await wait(() => expect(onSubmit).toHaveBeenCalled());
});
I am receiving "Error: Not implemented: HTMLFormElement.prototype.submit". I tried the solution mentioned here https://github.com/jsdom/jsdom/issues/1937 , but it did not work. I do not want to silence the errors but implement the test correctly. Thank you.
submit = jest.fn().mockImplementation((e) => e.preventDefault());
β Concoff