From 27945b492500bf497c9e5d479c54dfe77e6e502b Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 7 Jun 2024 16:57:37 +0100 Subject: [PATCH] chore: improve types in tests (#27293) --- test/nuxt/composables.test.ts | 8 ++++---- test/nuxt/nuxt-island.test.ts | 6 +++--- test/nuxt/plugin.test.ts | 7 ++++--- test/nuxt/tsconfig.json | 3 +++ tsconfig.json | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 test/nuxt/tsconfig.json diff --git a/test/nuxt/composables.test.ts b/test/nuxt/composables.test.ts index 02e12f7d87..d4bf1eaaa4 100644 --- a/test/nuxt/composables.test.ts +++ b/test/nuxt/composables.test.ts @@ -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(` { diff --git a/test/nuxt/nuxt-island.test.ts b/test/nuxt/nuxt-island.test.ts index 68faf38f72..e9cb75ae11 100644 --- a/test/nuxt/nuxt-island.test.ts +++ b/test/nuxt/nuxt-island.test.ts @@ -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(() => { diff --git a/test/nuxt/plugin.test.ts b/test/nuxt/plugin.test.ts index 02d8cef182..e2199a9b04 100644 --- a/test/nuxt/plugin.test.ts +++ b/test/nuxt/plugin.test.ts @@ -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)) diff --git a/test/nuxt/tsconfig.json b/test/nuxt/tsconfig.json new file mode 100644 index 0000000000..9e6718eb68 --- /dev/null +++ b/test/nuxt/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../.nuxt/tsconfig.json" +} diff --git a/tsconfig.json b/tsconfig.json index db885122b4..d36558a491 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -44,7 +44,8 @@ "**/examples/**", "**/docs/**", "**/playground/**", + "**/test/nuxt/**", "**/test/fixtures/**", - "test/nuxt/**" + "**/test/fixtures-temp/**" ] }