File tree Expand file tree Collapse file tree
src/components/Page/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 44
55import React from "react" ;
66import { render , screen } from "@testing-library/react" ;
7+ import "@testing-library/jest-dom" ;
78import { MemoryRouter } from "react-router" ;
89import 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+
2024describe ( "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 ( / f a i l e d t o l o a d c o n t e n t / i) ;
38+ expect ( errorElement ) . toBeInTheDocument ( ) ;
3439 } ) ;
3540} ) ;
You can’t perform that action at this time.
0 commit comments