Skip to content

Commit 92d11f6

Browse files
committed
make optional path param work
1 parent cbc1e81 commit 92d11f6

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest'
2-
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library'
2+
import {
3+
cleanup,
4+
fireEvent,
5+
render,
6+
screen,
7+
waitFor,
8+
} from '@solidjs/testing-library'
39
import {
410
Link,
511
Outlet,
@@ -701,21 +707,27 @@ describe('Solid Router - Optional Path Parameters', () => {
701707
)
702708

703709
const addCategoryBtn = await screen.findByTestId('add-category')
704-
const removeCategoryBtn = await screen.findByTestId('remove-category')
705710

706711
// Add category
707712
fireEvent.click(addCategoryBtn)
708-
expect(await screen.findByTestId('params')).toHaveTextContent(
709-
JSON.stringify({ category: 'tech' }),
710-
)
713+
await waitFor(() => {
714+
expect(screen.getByTestId('params')).toHaveTextContent(
715+
JSON.stringify({ category: 'tech' }),
716+
)
717+
})
711718
expect(router.state.location.pathname).toBe('/posts/tech')
712719

713-
// Remove category
720+
// Remove category - get fresh reference after navigation
721+
const removeCategoryBtn = await screen.findByTestId('remove-category')
714722
fireEvent.click(removeCategoryBtn)
715-
expect(await screen.findByTestId('params')).toHaveTextContent(
716-
JSON.stringify({}),
717-
)
718-
expect(router.state.location.pathname).toBe('/posts')
723+
await waitFor(() => {
724+
expect(router.state.location.pathname).toBe('/posts')
725+
})
726+
await waitFor(() => {
727+
expect(screen.getByTestId('params')).toHaveTextContent(
728+
JSON.stringify({}),
729+
)
730+
})
719731
})
720732
})
721733

0 commit comments

Comments
 (0)