test: add type test for nuxt module resolved types

This commit is contained in:
Daniel Roe 2024-06-11 12:41:34 +01:00
parent 41fc45da25
commit 115fc2d18f
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B

View File

@ -4,6 +4,7 @@ import type { FetchError } from 'ofetch'
import type { NavigationFailure, RouteLocationNormalized, RouteLocationRaw, Router, useRouter as vueUseRouter } from '#vue-router' import type { NavigationFailure, RouteLocationNormalized, RouteLocationRaw, Router, useRouter as vueUseRouter } from '#vue-router'
import type { AppConfig, RuntimeValue, UpperSnakeCase } from 'nuxt/schema' import type { AppConfig, RuntimeValue, UpperSnakeCase } from 'nuxt/schema'
import { defineNuxtModule } from 'nuxt/kit'
import { defineNuxtConfig } from 'nuxt/config' import { defineNuxtConfig } from 'nuxt/config'
import { callWithNuxt, isVue3 } from '#app' import { callWithNuxt, isVue3 } from '#app'
import type { NuxtError } from '#app' import type { NuxtError } from '#app'
@ -242,6 +243,17 @@ describe('modules', () => {
// @ts-expect-error we want to ensure we throw type error on invalid key // @ts-expect-error we want to ensure we throw type error on invalid key
defineNuxtConfig({ undeclaredKey: { other: false } }) defineNuxtConfig({ undeclaredKey: { other: false } })
}) })
it('preserves options in defineNuxtModule setup without `.with()`', () => {
defineNuxtModule<{ foo?: string, baz: number }>({
defaults: {
baz: 100,
},
setup: (resolvedOptions) => {
expectTypeOf(resolvedOptions).toEqualTypeOf<{ foo?: string, baz: number }>()
},
})
})
}) })
describe('nuxtApp', () => { describe('nuxtApp', () => {