Skip to content

Commit b26e9b7

Browse files
committed
correct waitFor usage
1 parent 25fa686 commit b26e9b7

3 files changed

Lines changed: 39 additions & 35 deletions

File tree

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5156,22 +5156,26 @@ describe('splat routes with empty splat', () => {
51565156
)
51575157

51585158
// When _splat has a value, it should follow the trailingSlash setting
5159-
expect(splatLinkWithEmptySplat.getAttribute('href')).toBe(`/splat${tail}`)
5160-
expect(splatLinkWithUndefinedSplat.getAttribute('href')).toBe(
5161-
`/splat${tail}`,
5162-
)
5163-
expect(splatLinkWithNoSplat.getAttribute('href')).toBe(`/splat${tail}`)
5164-
5165-
// Click the link with empty _splat and ensure the route matches
51665159
await waitFor(() => {
5167-
fireEvent.click(splatLinkWithEmptySplat)
5160+
expect(splatLinkWithEmptySplat.getAttribute('href')).toBe(
5161+
`/splat${tail}`,
5162+
)
5163+
expect(splatLinkWithUndefinedSplat.getAttribute('href')).toBe(
5164+
`/splat${tail}`,
5165+
)
5166+
expect(splatLinkWithNoSplat.getAttribute('href')).toBe(`/splat${tail}`)
51685167
})
51695168

5170-
expect(splatLinkWithEmptySplat).toHaveClass('active')
5171-
expect(splatLinkWithUndefinedSplat).toHaveClass('active')
5172-
expect(splatLinkWithNoSplat).toHaveClass('active')
5173-
expect(window.location.pathname).toBe(`/splat${tail}`)
5174-
expect(await screen.findByText('Splat Route')).toBeInTheDocument()
5169+
// Click the link with empty _splat and ensure the route matches
5170+
fireEvent.click(splatLinkWithEmptySplat)
5171+
5172+
await waitFor(async () => {
5173+
expect(splatLinkWithEmptySplat).toHaveClass('active')
5174+
expect(splatLinkWithUndefinedSplat).toHaveClass('active')
5175+
expect(splatLinkWithNoSplat).toHaveClass('active')
5176+
expect(window.location.pathname).toBe(`/splat${tail}`)
5177+
expect(await screen.findByText('Splat Route')).toBeInTheDocument()
5178+
})
51755179
},
51765180
)
51775181
})

‎packages/solid-router/tests/navigate.test.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
createRouter,
99
} from '../src'
1010
import type { RouterHistory } from '../src'
11+
import { waitFor } from '@solidjs/testing-library'
1112

1213
afterEach(() => {
1314
vi.clearAllMocks()
@@ -614,7 +615,10 @@ describe('splat routes with empty splat', () => {
614615
})
615616
await router.invalidate()
616617

617-
expect(router.state.location.pathname).toBe(`/splat${tail}`)
618+
await waitFor(() => {
619+
expect(router.state.location.pathname).toBe(`/splat${tail}`)
620+
})
621+
618622
// Navigate back to index
619623
await router.navigate({ to: '/' })
620624
await router.invalidate()

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

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,46 +2602,42 @@ describe('splat routes with empty splat', () => {
26022602
'splat-btn-with-empty-splat',
26032603
)
26042604

2605-
await waitFor(() => {
2606-
fireEvent.click(splatBtnWithEmptySplat)
2607-
})
2605+
fireEvent.click(splatBtnWithEmptySplat)
26082606

2609-
expect(window.location.pathname).toBe(`/splat${tail}`)
2610-
expect(await screen.findByText('Splat Route')).toBeInTheDocument()
2607+
await waitFor(async () => {
2608+
expect(window.location.pathname).toBe(`/splat${tail}`)
2609+
expect(await screen.findByText('Splat Route')).toBeInTheDocument()
2610+
})
26112611

26122612
// Navigate back to index
2613-
await waitFor(() => {
2614-
history.push('/')
2615-
})
2613+
history.push('/')
26162614

26172615
// Navigate with undefined _splat
26182616
const splatBtnWithUndefinedSplat = await screen.findByTestId(
26192617
'splat-btn-with-undefined-splat',
26202618
)
26212619

2622-
await waitFor(() => {
2623-
fireEvent.click(splatBtnWithUndefinedSplat)
2624-
})
2620+
fireEvent.click(splatBtnWithUndefinedSplat)
26252621

2626-
expect(window.location.pathname).toBe(`/splat${tail}`)
2627-
expect(await screen.findByText('Splat Route')).toBeInTheDocument()
2622+
await waitFor(async () => {
2623+
expect(window.location.pathname).toBe(`/splat${tail}`)
2624+
expect(await screen.findByText('Splat Route')).toBeInTheDocument()
2625+
})
26282626

26292627
// Navigate back to index
2630-
await waitFor(() => {
2631-
history.push('/')
2632-
})
2628+
history.push('/')
26332629

26342630
// Navigate with no _splat
26352631
const splatBtnWithNoSplat = await screen.findByTestId(
26362632
'splat-btn-with-no-splat',
26372633
)
26382634

2639-
await waitFor(() => {
2640-
fireEvent.click(splatBtnWithNoSplat)
2641-
})
2635+
fireEvent.click(splatBtnWithNoSplat)
26422636

2643-
expect(window.location.pathname).toBe(`/splat${tail}`)
2644-
expect(await screen.findByText('Splat Route')).toBeInTheDocument()
2637+
await waitFor(async () => {
2638+
expect(window.location.pathname).toBe(`/splat${tail}`)
2639+
expect(await screen.findByText('Splat Route')).toBeInTheDocument()
2640+
})
26452641
},
26462642
)
26472643
})

0 commit comments

Comments
 (0)