Skip to content

Commit e98d71e

Browse files
committedSep 5, 2023
test: avoid depending on specific number of ticks
1 parent de959c9 commit e98d71e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed
 

‎test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ describe('client-side nuxt features', () => {
3636

3737
it('allows pushing to other pages', async () => {
3838
await navigateTo('/something')
39-
expect(useNuxtApp().$router.currentRoute.value.path).toMatchInlineSnapshot(
40-
'"/something"'
39+
expect(useNuxtApp().$router.currentRoute.value.path).toEqual(
40+
'/something'
4141
)
42-
// It takes two more ticks for the Nuxt useRoute to be updated (as, after suspense resolves,
42+
// It takes a few ticks for the Nuxt useRoute to be updated (as, after suspense resolves,
4343
// we wait for a final hook and then update the injected route object )
44-
await nextTick()
45-
await nextTick()
46-
expect(useRoute().path).toMatchInlineSnapshot('"/something"')
44+
const route = useRoute()
45+
await new Promise<void>(resolve => {
46+
const unsub = watch(() => route.path, path => {
47+
if (path === '/something') {
48+
unsub()
49+
resolve()
50+
}
51+
})
52+
})
53+
expect(route.path).toEqual('/something')
4754
})
4855
})
4956

0 commit comments

Comments
 (0)
Please sign in to comment.