mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 21:25:11 +00:00
chore: improve types in tests (#27293)
This commit is contained in:
parent
601a2620b8
commit
27945b4925
@ -20,7 +20,6 @@ import { callOnce } from '#app/composables/once'
|
||||
import { useLoadingIndicator } from '#app/composables/loading-indicator'
|
||||
import { useRouteAnnouncer } from '#app/composables/route-announcer'
|
||||
|
||||
// @ts-expect-error virtual file
|
||||
import { asyncDataDefaults, nuxtDefaultErrorValue } from '#build/nuxt.config.mjs'
|
||||
|
||||
registerEndpoint('/api/test', defineEventHandler(event => ({
|
||||
@ -38,7 +37,6 @@ describe('app config', () => {
|
||||
`)
|
||||
updateAppConfig({
|
||||
new: 'value',
|
||||
// @ts-expect-error property does not exist
|
||||
nuxt: { nested: 42 },
|
||||
})
|
||||
expect(appConfig).toMatchInlineSnapshot(`
|
||||
@ -165,7 +163,7 @@ describe('useAsyncData', () => {
|
||||
|
||||
// https://github.com/nuxt/nuxt/issues/23411
|
||||
it('should initialize with error set to null when immediate: false', async () => {
|
||||
const { error, execute } = useAsyncData(() => ({}), { immediate: false })
|
||||
const { error, execute } = useAsyncData(() => Promise.resolve({}), { immediate: false })
|
||||
expect(error.value).toBe(asyncDataDefaults.errorValue)
|
||||
await execute()
|
||||
expect(error.value).toBe(asyncDataDefaults.errorValue)
|
||||
@ -217,7 +215,7 @@ describe('useAsyncData', () => {
|
||||
})
|
||||
|
||||
it('allows custom access to a cache', async () => {
|
||||
const { data } = await useAsyncData(() => ({ val: true }), { getCachedData: () => ({ val: false }) })
|
||||
const { data } = await useAsyncData(() => Promise.resolve({ val: true }), { getCachedData: () => ({ val: false }) })
|
||||
expect(data.value).toMatchInlineSnapshot(`
|
||||
{
|
||||
"val": false,
|
||||
@ -317,6 +315,7 @@ describe('useFetch', () => {
|
||||
|
||||
it('should timeout', async () => {
|
||||
const { status, error } = await useFetch(
|
||||
// @ts-expect-error should resolve to a string
|
||||
() => new Promise(resolve => setTimeout(resolve, 5000)),
|
||||
{ timeout: 1 },
|
||||
)
|
||||
@ -534,6 +533,7 @@ describe('loading state', () => {
|
||||
describe.skipIf(process.env.TEST_MANIFEST === 'manifest-off')('app manifests', () => {
|
||||
it('getAppManifest', async () => {
|
||||
const manifest = await getAppManifest()
|
||||
// @ts-expect-error timestamp is not optional
|
||||
delete manifest.timestamp
|
||||
expect(manifest).toMatchInlineSnapshot(`
|
||||
{
|
||||
|
@ -263,12 +263,12 @@ describe('client components', () => {
|
||||
const componentId = 'ClientWithSlot-12345'
|
||||
|
||||
vi.doMock(mockPath, () => ({
|
||||
default: {
|
||||
default: defineComponent({
|
||||
name: 'ClientWithSlot',
|
||||
setup (_, { slots }) {
|
||||
return () => h('div', { class: 'client-component' }, slots.default())
|
||||
return () => h('div', { class: 'client-component' }, slots.default?.())
|
||||
},
|
||||
},
|
||||
}),
|
||||
}))
|
||||
|
||||
const stubFetch = vi.fn(() => {
|
||||
|
@ -11,9 +11,10 @@ vi.mock('#app', async (original) => {
|
||||
}
|
||||
})
|
||||
|
||||
function pluginFactory (name: string, dependsOn?: string[], sequence: string[], parallel = true) {
|
||||
function pluginFactory (name: string, dependsOn: string[] | undefined, sequence: string[], parallel = true) {
|
||||
return defineNuxtPlugin({
|
||||
name,
|
||||
// @ts-expect-error we have a strong type for plugin names
|
||||
dependsOn,
|
||||
async setup () {
|
||||
sequence.push(`start ${name}`)
|
||||
@ -71,7 +72,7 @@ describe('plugin dependsOn', () => {
|
||||
pluginFactory('A', undefined, sequence),
|
||||
pluginFactory('B', ['A'], sequence),
|
||||
defineNuxtPlugin({
|
||||
name,
|
||||
name: 'some plugin',
|
||||
async setup () {
|
||||
sequence.push('start C')
|
||||
await new Promise(resolve => setTimeout(resolve, 5))
|
||||
@ -99,7 +100,7 @@ describe('plugin dependsOn', () => {
|
||||
const plugins = [
|
||||
pluginFactory('A', undefined, sequence),
|
||||
defineNuxtPlugin({
|
||||
name,
|
||||
name: 'some plugin',
|
||||
async setup () {
|
||||
sequence.push('start C')
|
||||
await new Promise(resolve => setTimeout(resolve, 50))
|
||||
|
3
test/nuxt/tsconfig.json
Normal file
3
test/nuxt/tsconfig.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../.nuxt/tsconfig.json"
|
||||
}
|
@ -44,7 +44,8 @@
|
||||
"**/examples/**",
|
||||
"**/docs/**",
|
||||
"**/playground/**",
|
||||
"**/test/nuxt/**",
|
||||
"**/test/fixtures/**",
|
||||
"test/nuxt/**"
|
||||
"**/test/fixtures-temp/**"
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user