diff --git a/src/vitest-environment-nuxt/runtime/mount.ts b/src/vitest-environment-nuxt/runtime/mount.ts index 6e0416afd..893e9d022 100644 --- a/src/vitest-environment-nuxt/runtime/mount.ts +++ b/src/vitest-environment-nuxt/runtime/mount.ts @@ -71,69 +71,74 @@ export async function mountSuspended( } } - return new Promise> & { setupState: any }>(resolve => { - const vm = mount( - { - setup: (props: Record, ctx: SetupContext) => { - setupContext = ctx - return NuxtRoot.setup(props, { - ...ctx, - expose: () => {}, - }) - }, - render: (renderContext: any) => - h( - Suspense, - { - onResolve: () => - nextTick().then(() => { - ;(vm as any).setupState = setupState - resolve(vm as any) - }), - }, - { - default: () => - h({ - async setup() { - const router = useRouter() - await router.replace(route) + return new Promise> & { setupState: any }>( + resolve => { + const vm = mount( + { + setup: (props: Record, ctx: SetupContext) => { + setupContext = ctx + return NuxtRoot.setup(props, { + ...ctx, + expose: () => {}, + }) + }, + render: (renderContext: any) => + h( + Suspense, + { + onResolve: () => + nextTick().then(() => { + ;(vm as any).setupState = setupState + resolve(vm as any) + }), + }, + { + default: () => + h({ + async setup() { + const router = useRouter() + await router.replace(route) - // Proxy top-level setup/render context so test wrapper resolves child component - const clonedComponent = { - ...component, - render: render - ? (_ctx: any, ...args: any[]) => { - // add all _ctx properties to renderContext - // the renderContext must remain intact, otherwise the emits don't work - for (const key in _ctx) { - renderContext[key] = _ctx[key] + // Proxy top-level setup/render context so test wrapper resolves child component + const clonedComponent = { + ...component, + render: render + ? (_ctx: any, ...args: any[]) => { + // add all _ctx properties to renderContext + // the renderContext must remain intact, otherwise the emits don't work + for (const key in _ctx) { + renderContext[key] = _ctx[key] + } + return render.apply(_ctx, [ + renderContext, + ...args, + ]) } - return render.apply(_ctx, [renderContext, ...args]) - } - : undefined, - setup: setup - ? (props: Record) => - wrappedSetup(props, setupContext) - : undefined, - } + : undefined, + setup: setup + ? (props: Record) => + wrappedSetup(props, setupContext) + : undefined, + } - return () => - h(clonedComponent, { ...props, ...attrs }, slots) - }, - }), - } - ), - }, - defu(_options, { - slots, - global: { - config: { - globalProperties: vueApp.config.globalProperties, - }, - provide: vueApp._context.provides, - components: { RouterLink }, + return () => + h(clonedComponent, { ...props, ...attrs }, slots) + }, + }), + } + ), }, - } satisfies ComponentMountingOptions) as ComponentMountingOptions - ) - }) + defu(_options, { + slots, + global: { + config: { + globalProperties: vueApp.config.globalProperties, + }, + provide: vueApp._context.provides, + components: { RouterLink }, + }, + } satisfies ComponentMountingOptions) as ComponentMountingOptions + ) + } + ) }