Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save armoredelephant/3bae7fe591b3456295b246e0d97c937a to your computer and use it in GitHub Desktop.
Save armoredelephant/3bae7fe591b3456295b246e0d97c937a to your computer and use it in GitHub Desktop.
ContactForm.test.tsx
import { render, fireEvent, screen } from "@testing-library/react";
import ContactForm from "../ContactForm";
describe("<ContactForm />", () => {
beforeEach(() => {
render(<ContactForm />);
});
test("should display required errors when fields are invalid", async () => {
fireEvent.submit(screen.getByRole("button"), {
preventDefault: () => {},
});
expect(await screen.findAllByRole("alert")).toHaveLength(3);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment