diff --git a/src/vitest-environment-nuxt/index.ts b/src/vitest-environment-nuxt/index.ts index b1c738403..e433b4215 100644 --- a/src/vitest-environment-nuxt/index.ts +++ b/src/vitest-environment-nuxt/index.ts @@ -12,7 +12,10 @@ import { export default { name: 'nuxt', async setup(_, environmentOptions) { - const win = new (GlobalWindow || Window)() as any as Window & { + const win = new (GlobalWindow || Window)({ + // Happy-dom defaults to `about:blank` + url: 'http://localhost:3000', + }) as any as Window & { __app: App __registry: Set __NUXT__: any diff --git a/test/fixtures/nuxt-vitest/nuxt.config.ts b/test/fixtures/nuxt-vitest/nuxt.config.ts index 760d1432c..6e99f9145 100644 --- a/test/fixtures/nuxt-vitest/nuxt.config.ts +++ b/test/fixtures/nuxt-vitest/nuxt.config.ts @@ -1,5 +1,8 @@ // https://v3.nuxtjs.org/api/configuration/nuxt.config export default defineNuxtConfig({ + app: { + rootId: 'nuxt-test', + }, modules: [ '../packages/nuxt-vitest/src/module', '@nuxt/devtools', diff --git a/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts b/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts index 51aeb597e..0bd004ba0 100644 --- a/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts +++ b/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts @@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest' import { mountSuspended, registerEndpoint } from 'vitest-environment-nuxt/utils' +import { watch } from 'vue' import App from '~/app.vue' import FetchComponent from '~/components/FetchComponent.vue' import OptionsComponent from '~/components/OptionsComponent.vue' @@ -29,16 +30,24 @@ describe('client-side nuxt features', () => { it('defaults to index page', async () => { expect(useRoute().matched[0].meta).toMatchInlineSnapshot(` { - "slug": "foo", + "value": "set in index", } `) // TODO: should it be possible to push to other routes? }) - it('allows pushing to other pages', async () => { - await useRouter().push('/something') - expect(useRoute().fullPath).toMatchInlineSnapshot('"/something"') - }) + it('allows pushing to other pages', async () => + new Promise(done => { + useRouter() + .push('/something') + .then(() => { + const stop = watch(useRoute(), () => { + expect(useRoute().fullPath).toMatchInlineSnapshot('"/something"') + stop() + done() + }) + }) + })) }) describe('test utils', () => {