Skip to content

Commit e93ef8d

Browse files
committed
test(Page): add unit test for content.__error rendering and fix test setup
1 parent 2b848f6 commit e93ef8d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/components/Page/__tests__/Page.test.js renamed to src/components/Page/__tests__/Page.test.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import React from "react";
66
import { render, screen } from "@testing-library/react";
7+
import "@testing-library/jest-dom";
78
import { MemoryRouter } from "react-router";
89
import Page from "../Page";
910

@@ -17,8 +18,11 @@ jest.mock("react-router", () => ({
1718
useLocation: () => ({ pathname: "/test", hash: "" }),
1819
}));
1920

21+
// Mock scrollTo (jsdom doesn't support it)
22+
window.scrollTo = jest.fn();
23+
2024
describe("Page component", () => {
21-
it("renders error message when content.__error exists", () => {
25+
it("renders error message when content.__error exists", async () => {
2226
const content = {
2327
__error: true,
2428
message: "Failed to load content",
@@ -30,6 +34,7 @@ describe("Page component", () => {
3034
</MemoryRouter>,
3135
);
3236

33-
expect(screen.getByText("Failed to load content")).toBeInTheDocument();
37+
const errorElement = await screen.findByText(/failed to load content/i);
38+
expect(errorElement).toBeInTheDocument();
3439
});
3540
});

0 commit comments

Comments
 (0)