Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
fix: properly set default route (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarols authored Jun 28, 2023
1 parent 9f8dd2c commit 674ede3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
5 changes: 4 additions & 1 deletion packages/vitest-environment-nuxt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
export default <Environment>{
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<string>
__NUXT__: any
Expand Down
3 changes: 3 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
19 changes: 14 additions & 5 deletions playground/tests/nuxt/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<void>(done => {
useRouter()
.push('/something')
.then(() => {
const stop = watch(useRoute(), () => {
expect(useRoute().fullPath).toMatchInlineSnapshot('"/something"')
stop()
done()
})
})
}))
})

describe('test utils', () => {
Expand Down

0 comments on commit 674ede3

Please sign in to comment.