Skip to content

Instantly share code, notes, and snippets.

@armoredelephant
Last active July 25, 2020 21:54
Show Gist options
  • Save armoredelephant/68d6cb9fa9806ad7d55306e273f5e690 to your computer and use it in GitHub Desktop.
Save armoredelephant/68d6cb9fa9806ad7d55306e273f5e690 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