From 7df6be28ca9d3abb9e49bf572d773a5515c49fab Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sun, 24 Sep 2023 10:20:32 +0200 Subject: [PATCH] test: update test to use server rather than live api --- test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts b/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts index f5c3f8ff9..897322b73 100644 --- a/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts +++ b/test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts @@ -2,6 +2,9 @@ import { describe, it, expect } from 'vitest' import { mountSuspended, registerEndpoint } from 'vitest-environment-nuxt/utils' +import { listen } from 'listhen' +import { createApp, eventHandler, toNodeListener } from 'h3' + import App from '~/app.vue' import FetchComponent from '~/components/FetchComponent.vue' import OptionsComponent from '~/components/OptionsComponent.vue' @@ -111,10 +114,12 @@ describe('test utils', () => { `) }) - it('can use $fetch', () => { - expect( - $fetch('https://jsonplaceholder.typicode.com/todos/1') - ).resolves.toMatchObject({ id: 1 }) + it('can use $fetch', async () => { + const app = createApp().use('/todos/1', eventHandler(() => ({ id: 1 }))) + const server = await listen(toNodeListener(app)) + const [{ url }] = await server.getURLs() + expect(await $fetch('/todos/1', { baseURL: url })).toMatchObject({ id: 1 }) + await server.close() }) it('can mock fetch requests', async () => {