Skip to content

Commit 7df6be2

Browse files
committedSep 26, 2023
test: update test to use server rather than live api
1 parent bc5e9ce commit 7df6be2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed
 

‎test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { describe, it, expect } from 'vitest'
22

33
import { mountSuspended, registerEndpoint } from 'vitest-environment-nuxt/utils'
44

5+
import { listen } from 'listhen'
6+
import { createApp, eventHandler, toNodeListener } from 'h3'
7+
58
import App from '~/app.vue'
69
import FetchComponent from '~/components/FetchComponent.vue'
710
import OptionsComponent from '~/components/OptionsComponent.vue'
@@ -111,10 +114,12 @@ describe('test utils', () => {
111114
`)
112115
})
113116

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()
118123
})
119124

120125
it('can mock fetch requests', async () => {

0 commit comments

Comments
 (0)