Skip to content

Commit

Permalink
Reverse validation order
Browse files Browse the repository at this point in the history
Fixes the test coverage because isValidEmail fails first
amattu2 committed Jan 28, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3f039ad commit 671f338
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/components/Footer/NewsletterForm.test.tsx
Original file line number Diff line number Diff line change
@@ -89,6 +89,18 @@ describe("Implementation Requirements", () => {
}
);

it("should not submit the newsletter form if the email is invalid (empty)", async () => {
const { getByTestId } = render(<NewsletterForm data-testid="newsletter-form" />);

userEvent.click(
within(getByTestId("newsletter-form")).getByRole("button", {
name: "Sign up",
})
);

expect(mockWindowOpen).not.toHaveBeenCalled();
});

it("should submit the form to the correct URL", async () => {
const { getByTestId } = render(<NewsletterForm data-testid="newsletter-form" />);

2 changes: 1 addition & 1 deletion src/components/Footer/NewsletterForm.tsx
Original file line number Diff line number Diff line change
@@ -77,8 +77,8 @@ const NewsletterForm: FC<NewsletterFormProps> = forwardRef<
className="signUpInputBox"
{...register("email", {
validate: {
validEmail: isValidEmail,
notEmpty: isNotEmpty,
validEmail: isValidEmail,
},
required: "This field is required.",
})}

0 comments on commit 671f338

Please sign in to comment.