Skip to content

Commit

Permalink
test: update test to use server rather than live api
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Sep 26, 2023
1 parent bc5e9ce commit 7df6be2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/fixtures/nuxt-vitest/tests/nuxt/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<unknown>('/todos/1', { baseURL: url })).toMatchObject({ id: 1 })
await server.close()
})

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

0 comments on commit 7df6be2

Please sign in to comment.