Skip to content

Commit

Permalink
test: avoid depending on specific number of ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Sep 5, 2023
1 parent de959c9 commit e98d71e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ describe('client-side nuxt features', () => {

it('allows pushing to other pages', async () => {
await navigateTo('/something')
expect(useNuxtApp().$router.currentRoute.value.path).toMatchInlineSnapshot(
'"/something"'
expect(useNuxtApp().$router.currentRoute.value.path).toEqual(
'/something'
)
// It takes two more ticks for the Nuxt useRoute to be updated (as, after suspense resolves,
// It takes a few ticks for the Nuxt useRoute to be updated (as, after suspense resolves,
// we wait for a final hook and then update the injected route object )
await nextTick()
await nextTick()
expect(useRoute().path).toMatchInlineSnapshot('"/something"')
const route = useRoute()
await new Promise<void>(resolve => {
const unsub = watch(() => route.path, path => {
if (path === '/something') {
unsub()
resolve()
}
})
})
expect(route.path).toEqual('/something')
})
})

Expand Down

0 comments on commit e98d71e

Please sign in to comment.