import { expectTypeOf } from 'expect-type' import { describe, it } from 'vitest' import type { Ref } from 'vue' import { useRouter as vueUseRouter } from 'vue-router' import { defineNuxtConfig } from '~~/../../packages/nuxt3/src' import { useRouter } from '#imports' import { isVue3 } from '#app' interface TestResponse { message: string } describe('API routes', () => { it('generates types for routes', () => { expectTypeOf($fetch('/api/hello')).toMatchTypeOf>() expectTypeOf($fetch('/api/hey')).toMatchTypeOf>() expectTypeOf($fetch('/api/other')).toMatchTypeOf>() expectTypeOf($fetch('/test')).toMatchTypeOf>() }) it('works with useFetch', () => { expectTypeOf(useFetch('/api/hello').data).toMatchTypeOf>() expectTypeOf(useFetch('/api/hey').data).toMatchTypeOf>() expectTypeOf(useFetch('/api/hey', { pick: ['baz'] }).data).toMatchTypeOf>() expectTypeOf(useFetch('/api/other').data).toMatchTypeOf>() expectTypeOf(useFetch('/test').data).toMatchTypeOf>() expectTypeOf(useLazyFetch('/api/hello').data).toMatchTypeOf>() expectTypeOf(useLazyFetch('/api/hey').data).toMatchTypeOf>() expectTypeOf(useLazyFetch('/api/hey', { pick: ['baz'] }).data).toMatchTypeOf>() expectTypeOf(useLazyFetch('/api/other').data).toMatchTypeOf>() expectTypeOf(useLazyFetch('/api/other').data).toMatchTypeOf>() expectTypeOf(useLazyFetch('/test').data).toMatchTypeOf>() }) }) describe('aliases', () => { it('allows importing from path aliases', () => { expectTypeOf(useRouter).toMatchTypeOf() expectTypeOf(isVue3).toMatchTypeOf() }) }) describe('middleware', () => { it('recognises named middleware', () => { definePageMeta({ middleware: 'test-middleware' }) definePageMeta({ middleware: 'pascal-case' }) // @ts-expect-error Invalid middleware definePageMeta({ middleware: 'invalid-middleware' }) }) }) describe('layouts', () => { it('recognises named layouts', () => { definePageMeta({ layout: 'test-layout' }) definePageMeta({ layout: 'pascal-case' }) // @ts-expect-error Invalid layout definePageMeta({ layout: 'invalid-layout' }) }) }) describe('modules', () => { it('augments schema automatically', () => { defineNuxtConfig({ sampleModule: { enabled: false } }) // @ts-expect-error defineNuxtConfig({ sampleModule: { other: false } }) // @ts-expect-error defineNuxtConfig({ undeclaredKey: { other: false } }) }) })