Skip to content

Commit

Permalink
Merge pull request #21 from Gpx/form-submit
Browse files Browse the repository at this point in the history
test: πŸ’ add tests for form submit
  • Loading branch information
Gpx committed Sep 30, 2018
2 parents 91545d5 + f35c97c commit 728deae
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions __tests__/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,26 @@ describe("fireEvent.click", () => {
userEvent.click(getByTestId("label"));
expect(getByTestId("input")).toHaveProperty("checked", true);
});

it("should submit a form when clicking on a <button>", () => {
const onSubmit = jest.fn();
const { getByText } = render(
<form onSubmit={onSubmit}>
<button>Submit</button>
</form>
);
userEvent.click(getByText("Submit"));
expect(onSubmit).toHaveBeenCalledTimes(1);
});

it('should not submit a form when clicking on a <button type="button">', () => {
const onSubmit = jest.fn();
const { getByText } = render(
<form onSubmit={onSubmit}>
<button type="button">Submit</button>
</form>
);
userEvent.click(getByText("Submit"));
expect(onSubmit).not.toHaveBeenCalled();
});
});

0 comments on commit 728deae

Please sign in to comment.