[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-vitest. An vitest environment with support for testing code that needs a Nuxt runtime environment
nuxt nuxt-module testing unit-testing vitest
0

Configure Feed

Select the types of activity you want to include in your feed.

test: update test to use server rather than live api

Daniel Roe (Sep 26, 2023, 2:19 AM +0200) b05c3f60 ed16b970

+9 -4
+9 -4
playground/tests/nuxt/index.spec.ts
··· 2 2 3 3 import { mountSuspended, registerEndpoint } from 'vitest-environment-nuxt/utils' 4 4 5 + import { listen } from 'listhen' 6 + import { createApp, eventHandler, toNodeListener } from 'h3' 7 + 5 8 import App from '~/app.vue' 6 9 import FetchComponent from '~/components/FetchComponent.vue' 7 10 import OptionsComponent from '~/components/OptionsComponent.vue' ··· 111 114 `) 112 115 }) 113 116 114 - it('can use $fetch', () => { 115 - expect( 116 - $fetch('https://jsonplaceholder.typicode.com/todos/1') 117 - ).resolves.toMatchObject({ id: 1 }) 117 + it('can use $fetch', async () => { 118 + const app = createApp().use('/todos/1', eventHandler(() => ({ id: 1 }))) 119 + const server = await listen(toNodeListener(app)) 120 + const [{ url }] = await server.getURLs() 121 + expect(await $fetch<unknown>('/todos/1', { baseURL: url })).toMatchObject({ id: 1 }) 122 + await server.close() 118 123 }) 119 124 120 125 it('can mock fetch requests', async () => {