Skip to content

Commit

Permalink
Add tests for AppFallback component
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-slobodian committed Oct 25, 2024
1 parent ce9ff6a commit 3755de5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/components/app-fallback/AppFallback.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { render, screen, userEvent } from "@testing";
import { AppFallback } from "./AppFallback";

describe("<AppFallback />", () => {
it("Should render and handle click", async () => {
const resetErrorBoundaryMock = vi.fn();
render(
<AppFallback resetErrorBoundary={resetErrorBoundaryMock} error={""} />
);

expect(screen.getByText(/Oops! Something went wrong/)).toBeInTheDocument();
expect(
screen.getByText(/Sorry, an error has occurred. Please try again/)
).toBeInTheDocument();

expect(
screen.getByRole("link", {
name: "Home page",
})
).toHaveAttribute("href", "/");

await userEvent.click(screen.getByRole("button", { name: /Try again/ }));

expect(resetErrorBoundaryMock).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 3755de5

Please sign in to comment.