From e98d71ea10eb006ab6321e18a17e49f4de171121 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 5 Sep 2023 14:38:30 +0100 Subject: [PATCH] test: avoid depending on specific number of ticks --- .../nuxt-vitest/tests/nuxt/index.spec.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts b/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts index 477260e64..f5c3f8ff9 100644 --- a/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts +++ b/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts @@ -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(resolve => { + const unsub = watch(() => route.path, path => { + if (path === '/something') { + unsub() + resolve() + } + }) + }) + expect(route.path).toEqual('/something') }) })