@@ -4,8 +4,6 @@ import { testWithRouter } from '../__tests__/test-with-router';
44import { Navigation } from './Navigation' ;
55
66testWithRouter ( 'renders a sidebar link for each top-level page' , async ( { render } ) => {
7- window . history . pushState ( null , '' , '/' ) ;
8-
97 const { getByText, unmount } = await render ( < Navigation /> ) ;
108
119 await expect . element ( getByText ( 'Home' ) ) . toBeInTheDocument ( ) ;
@@ -16,30 +14,26 @@ testWithRouter('renders a sidebar link for each top-level page', async ({ render
1614 await unmount ( ) ;
1715} ) ;
1816
19- testWithRouter ( 'navigating to a page updates the URL' , async ( { render } ) => {
20- window . history . pushState ( null , '' , '/' ) ;
21-
17+ testWithRouter ( 'navigating to a page updates the URL' , async ( { render, app } ) => {
2218 const { getByText, unmount } = await render ( < Navigation /> ) ;
2319
2420 await getByText ( 'Products' ) . click ( ) ;
2521
26- expect ( window . location . pathname ) . toBe ( '/products' ) ;
22+ await vi . waitFor ( ( ) => expect ( app . navigation . path . pathname ) . toBe ( '/products' ) ) ;
2723
2824 await unmount ( ) ;
2925} ) ;
3026
31- testWithRouter ( 'the active link swaps when navigating to a different page' , async ( { render } ) => {
32- window . history . pushState ( null , '' , '/' ) ;
33-
27+ testWithRouter ( 'the active link swaps when navigating to a different page' , async ( { render, app } ) => {
3428 const { getByText, unmount } = await render ( < Navigation /> ) ;
3529
3630 // active state is only reflected as a styled-components color, not a DOM attribute
3731 const colorOf = ( label : string ) => getComputedStyle ( getByText ( label ) . element ( ) ) . color ;
3832
3933 // navigate via the router's own click handler first, so its internal location is
40- // guaranteed to be in sync with the URL rather than relying on the initial pushState above
34+ // guaranteed to be in sync rather than relying on the initial location above
4135 await getByText ( 'Home' ) . click ( ) ;
42- await vi . waitFor ( ( ) => expect ( window . location . pathname ) . toBe ( '/' ) ) ;
36+ await vi . waitFor ( ( ) => expect ( app . navigation . path . pathname ) . toBe ( '/' ) ) ;
4337
4438 // Users is never navigated to in this test, so its color is a stable "inactive" reference
4539 const inactiveColor = colorOf ( 'Users' ) ;
0 commit comments