Skip to content

Commit

Permalink
fix(runtime-utils): don't stub helpers when shallow (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Dec 5, 2023
1 parent 92f6a65 commit 55cbda2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
10 changes: 10 additions & 0 deletions examples/app-vitest-full/tests/nuxt/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ describe('test utils', () => {
`)
})

it('should work with shallow mounting within suspense', async () => {
const component = await mountSuspended(App, { shallow: true })
expect(component.html()).toMatchInlineSnapshot(`
"<async-component-wrapper-stub></async-component-wrapper-stub>
<anonymous-stub></anonymous-stub>
<nuxt-page-stub></nuxt-page-stub>
<nuxt-link-stub to="/test"></nuxt-link-stub>"
`)
})

it('should render default props within nuxt suspense', async () => {
const component = await mountSuspended(OptionsComponent)
expect(component.find('h2').html()).toMatchInlineSnapshot(
Expand Down
28 changes: 19 additions & 9 deletions src/runtime-utils/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ export async function mountSuspended<T>(
{
default: () =>
h({
name: 'MountSuspendedHelper',
async setup() {
const router = useRouter()
await router.replace(route)

// Proxy top-level setup/render context so test wrapper resolves child component
const clonedComponent = {
name: 'MountSuspendedComponent',
...component,
render: render
? (_ctx: any, ...args: any[]) => {
Expand Down Expand Up @@ -127,16 +129,24 @@ export async function mountSuspended<T>(
}
),
},
defu(_options, {
slots,
global: {
config: {
globalProperties: vueApp.config.globalProperties,
defu(
_options,
{
slots,
global: {
config: {
globalProperties: vueApp.config.globalProperties,
},
provide: vueApp._context.provides,
stubs: {
Suspense: false,
MountSuspendedHelper: false,
[typeof (component as any).name === 'string' ? (component as any).name : 'MountSuspendedComponent']: false
},
components: { RouterLink },
},
provide: vueApp._context.provides,
components: { RouterLink },
},
} satisfies ComponentMountingOptions<T>) as ComponentMountingOptions<T>
} satisfies ComponentMountingOptions<T>
) as ComponentMountingOptions<T>
)
}
)
Expand Down

0 comments on commit 55cbda2

Please sign in to comment.