Skip to content

Commit 3f4a9da

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

3 files changed

Lines changed: 2830 additions & 2433 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"@svgr/webpack": "^8.1.0",
101101
"@tailwindcss/postcss": "^4.2.1",
102102
"@testing-library/dom": "^10.4.1",
103+
"@testing-library/jest-dom": "^6.9.1",
103104
"@testing-library/react": "^16.3.2",
104105
"autoprefixer": "^10.4.27",
105106
"babel-loader": "^10.1.1",

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)