Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Nov 20, 2023
1 parent b8d2697 commit 8b428b4
Showing 1 changed file with 66 additions and 61 deletions.
127 changes: 66 additions & 61 deletions src/vitest-environment-nuxt/runtime/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,69 +71,74 @@ export async function mountSuspended<T>(
}
}

return new Promise<ReturnType<typeof mount<T>> & { setupState: any }>(resolve => {
const vm = mount(
{
setup: (props: Record<string, any>, 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<ReturnType<typeof mount<T>> & { setupState: any }>(
resolve => {
const vm = mount(
{
setup: (props: Record<string, any>, 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<string, any>) =>
wrappedSetup(props, setupContext)
: undefined,
}
: undefined,
setup: setup
? (props: Record<string, any>) =>
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<T>) as ComponentMountingOptions<T>
)
})
defu(_options, {
slots,
global: {
config: {
globalProperties: vueApp.config.globalProperties,
},
provide: vueApp._context.provides,
components: { RouterLink },
},
} satisfies ComponentMountingOptions<T>) as ComponentMountingOptions<T>
)
}
)
}

0 comments on commit 8b428b4

Please sign in to comment.