Skip to content

Commit

Permalink
fix(runtime-utils): pass global directives to mountSuspended (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-wenzel authored Oct 3, 2024
1 parent 8a9d95d commit 73b8d7a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/app-vitest-full/components/DirectiveComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div v-sample-directive />
</template>
7 changes: 7 additions & 0 deletions examples/app-vitest-full/plugins/directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.directive('sample-directive', {
created(el: Element) {
el.setAttribute('data-directive', 'true')
},
})
})
6 changes: 6 additions & 0 deletions examples/app-vitest-full/tests/nuxt/mount-suspended.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ExportDefaultWithRenderComponent from '~/components/ExportDefaultWithRend
import ExportDefaultReturnsRenderComponent from '~/components/ExportDefaultReturnsRenderComponent.vue'

import { BoundAttrs } from '#components'
import DirectiveComponent from '~/components/DirectiveComponent.vue'

const formats = {
ExportDefaultComponent,
Expand Down Expand Up @@ -117,6 +118,11 @@ describe('mountSuspended', () => {
// @ts-expect-error FIXME: someRef is typed as unwrapped
expect(component.vm.someRef.value).toBe('thing')
})

it('respects directives registered in nuxt plugins', async () => {
const component = await mountSuspended(DirectiveComponent)
expect(component.html()).toMatchInlineSnapshot(`"<div data-directive="true"></div>"`)
})
})

describe.each(Object.entries(formats))(`%s`, (name, component) => {
Expand Down
1 change: 1 addition & 0 deletions src/runtime-utils/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export async function mountSuspended<T>(
config: {
globalProperties: vueApp.config.globalProperties,
},
directives: vueApp._context.directives,
provide: vueApp._context.provides,
stubs: {
Suspense: false,
Expand Down

0 comments on commit 73b8d7a

Please sign in to comment.