Skip to content

Commit 7eb3a1d

Browse files
committed
add waitFor
1 parent 6a9901c commit 7eb3a1d

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ describe('Link', () => {
393393
// navigate to /?foo=bar
394394
fireEvent.click(indexFooBarLink)
395395

396+
// Wait for navigation to complete
397+
await waitFor(() => {
398+
expect(indexFooBarLink).toHaveClass('active')
399+
})
400+
396401
expect(indexExactLink).toHaveClass('inactive')
397402
expect(indexExactLink).not.toHaveClass('active')
398403
expect(indexExactLink).toHaveAttribute('href', '/')
@@ -777,11 +782,15 @@ describe('Link', () => {
777782
const updatedFilter = await screen.findByTestId('current-filter')
778783

779784
// Verify search was updated
785+
await waitFor(() => {
786+
expect(window.location.search).toBe('?page=2&filter=inactive')
787+
})
780788
expect(window.location.pathname).toBe('/posts')
781-
expect(window.location.search).toBe('?page=2&filter=inactive')
782789

783-
expect(updatedPage).toHaveTextContent('Page: 2')
784-
expect(updatedFilter).toHaveTextContent('Filter: inactive')
790+
await waitFor(() => {
791+
expect(updatedPage).toHaveTextContent('Page: 2')
792+
expect(updatedFilter).toHaveTextContent('Filter: inactive')
793+
})
785794
})
786795

787796
test('when navigation to . from /posts while updating search from / and using base path', async () => {
@@ -888,13 +897,17 @@ describe('Link', () => {
888897

889898
await screen.findByTestId('current-page')
890899
// Verify search was updated
900+
await waitFor(() => {
901+
expect(window.location.search).toBe('?page=2&filter=inactive')
902+
})
891903
expect(window.location.pathname).toBe('/Dashboard/posts')
892-
expect(window.location.search).toBe('?page=2&filter=inactive')
893904

894905
const updatedPage = await screen.findByTestId('current-page')
895906
const updatedFilter = await screen.findByTestId('current-filter')
896-
expect(updatedPage).toHaveTextContent('Page: 2')
897-
expect(updatedFilter).toHaveTextContent('Filter: inactive')
907+
await waitFor(() => {
908+
expect(updatedPage).toHaveTextContent('Page: 2')
909+
expect(updatedFilter).toHaveTextContent('Filter: inactive')
910+
})
898911
})
899912

900913
test('when navigating to /posts with invalid search', async () => {

packages/solid-router/tests/optional-path-params.test.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,13 +651,19 @@ describe('Solid Router - Optional Path Parameters', () => {
651651
const navigateSpecific = await screen.findByTestId('navigate-specific')
652652

653653
fireEvent.click(navigateAll)
654-
expect(router.state.location.pathname).toBe('/posts')
654+
await waitFor(() => {
655+
expect(router.state.location.pathname).toBe('/posts')
656+
})
655657

656658
fireEvent.click(navigateTech)
657-
expect(router.state.location.pathname).toBe('/posts/tech')
659+
await waitFor(() => {
660+
expect(router.state.location.pathname).toBe('/posts/tech')
661+
})
658662

659663
fireEvent.click(navigateSpecific)
660-
expect(router.state.location.pathname).toBe('/posts/tech/hello-world')
664+
await waitFor(() => {
665+
expect(router.state.location.pathname).toBe('/posts/tech/hello-world')
666+
})
661667
})
662668

663669
it('should handle relative navigation with optional parameters', async () => {

packages/solid-router/tests/store-updates-during-navigation.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ describe("Store doesn't update *too many* times during navigation", () => {
184184
// This number should be as small as possible to minimize the amount of work
185185
// that needs to be done during a navigation.
186186
// Any change that increases this number should be investigated.
187-
expect(updates).toBeGreaterThanOrEqual(6) // WARN: this is flaky, and sometimes (rarely) is 7
188-
expect(updates).toBeLessThanOrEqual(7)
187+
expect(updates).toBeGreaterThanOrEqual(6) // WARN: this is flaky, and sometimes (rarely) is 8
188+
expect(updates).toBeLessThanOrEqual(8)
189189
})
190190

191191
test('not found in beforeLoad', async () => {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,9 +1302,11 @@ test('when setting search params with 2 parallel navigate calls', async () => {
13021302
render(() => <RouterProvider router={router} />)
13031303

13041304
// console.log(router.state.location)
1305-
expect(router.state.location.search).toEqual({
1306-
param1: 'param1-default',
1307-
param2: 'param2-default',
1305+
await waitFor(() => {
1306+
expect(router.state.location.search).toEqual({
1307+
param1: 'param1-default',
1308+
param2: 'param2-default',
1309+
})
13081310
})
13091311

13101312
const postsButton = await screen.findByRole('button', { name: 'search' })

0 commit comments

Comments
 (0)