Skip to content

Commit 2d338e0

Browse files
authored
test(router): wait for nav to complete (#5744)
1 parent 219b72c commit 2d338e0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/react-router/tests/link.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,11 @@ describe('Link', () => {
748748

749749
await act(() => fireEvent.click(updateSearchLink))
750750

751+
// Wait for navigation to complete and search params to update
752+
await waitFor(() => {
753+
expect(window.location.search).toBe('?page=2&filter=inactive')
754+
})
755+
751756
// Verify search was updated
752757
expect(window.location.pathname).toBe('/posts')
753758
expect(window.location.search).toBe('?page=2&filter=inactive')
@@ -860,6 +865,11 @@ describe('Link', () => {
860865

861866
await act(() => fireEvent.click(updateSearchLink))
862867

868+
// Wait for navigation to complete and search params to update
869+
await waitFor(() => {
870+
expect(window.location.search).toBe('?page=2&filter=inactive')
871+
})
872+
863873
// Verify search was updated
864874
expect(window.location.pathname).toBe('/Dashboard/posts')
865875
expect(window.location.search).toBe('?page=2&filter=inactive')

packages/solid-router/tests/link.test.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,12 @@ describe('Link', () => {
775775
'/posts?page=2&filter=inactive',
776776
)
777777

778-
fireEvent.click(updateSearchLink)
778+
await fireEvent.click(updateSearchLink)
779+
780+
// Wait for navigation to complete and search params to update
781+
await waitFor(() => {
782+
expect(window.location.search).toBe('?page=2&filter=inactive')
783+
})
779784

780785
const updatedPage = await screen.findByTestId('current-page')
781786
const updatedFilter = await screen.findByTestId('current-filter')
@@ -888,7 +893,12 @@ describe('Link', () => {
888893
'/Dashboard/posts?page=2&filter=inactive',
889894
)
890895

891-
fireEvent.click(updateSearchLink)
896+
await fireEvent.click(updateSearchLink)
897+
898+
// Wait for navigation to complete and search params to update
899+
await waitFor(() => {
900+
expect(window.location.search).toBe('?page=2&filter=inactive')
901+
})
892902

893903
await screen.findByTestId('current-page')
894904
// Verify search was updated

0 commit comments

Comments
 (0)