Design comparison
Solution retrospective
What are you most proud of, and what would you do differently next time?
Testing
Originally I wanted to use Jest
to do testing, but then it turned out that it was too complicated to setup.
Here, I used screen.getByTestId
to get the element, using userEvent.type
, userEvant.click
from @testing-library/user-event
library to mock the keyboard input and the clicking event.
// ----------- //
import { describe, it, expect } from "vitest"
import {
render,
screen,
waitfor } from "@testing-library/react"
import App from "./App"
describe("test form", () => {
it("submit wrong email", async () => {
render();
const emailInput = screen.getByTestId("email-input");
const submitBtn = screen.getByTestId("submit-btn");
await userEvent.type(emailInput, "asdasd");
await userEvent.click(submitBtn);
await waitFor(() => {
const errorMsg = screen.getByText("Please provide a valid email");
expect(errorMsg).toBeInTheDocument();
});
});
})
Community feedback
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord