Skip to content

Commit

Permalink
fix(mountSuspended): define $attrs in component render context
Browse files Browse the repository at this point in the history
  • Loading branch information
romhml committed Feb 1, 2025
1 parent 77ecce9 commit bf54c86
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/app-vitest-full/components/ComponentWithAttrs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<span v-bind="$attrs" />
</template>

<script setup lang="ts">
defineOptions({
inheritAttrs: false,
})
</script>
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 @@ -14,6 +14,7 @@ import ExportDefineComponent from '~/components/ExportDefineComponent.vue'
import ExportDefaultWithRenderComponent from '~/components/ExportDefaultWithRenderComponent.vue'
import ExportDefaultReturnsRenderComponent from '~/components/ExportDefaultReturnsRenderComponent.vue'
import OptionsApiPage from '~/pages/other/options-api.vue'
import ComponentWithAttrs from '~/components/ComponentWithAttrs.vue'
import ComponentWithReservedProp from '~/components/ComponentWithReservedProp.vue'
import ComponentWithReservedState from '~/components/ComponentWithReservedState.vue'
import ComponentWithImports from '~/components/ComponentWithImports.vue'
Expand Down Expand Up @@ -159,6 +160,11 @@ describe('mountSuspended', () => {
expect(span.text()).toBe('false')
})

it('should define $attrs', async () => {
const component = await mountSuspended(ComponentWithAttrs, { attrs: { foo: 'bar' } })
expect(component.find('[foo="bar"]').exists()).toBe(true)
})

describe('Options API', () => {
beforeEach(() => {
vi.spyOn(console, 'error').mockImplementation((message) => {
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 @@ -182,6 +182,7 @@ export async function mountSuspended<T>(
_options,
{
slots,
attrs,
global: {
config: {
globalProperties: vueApp.config.globalProperties,
Expand Down

0 comments on commit bf54c86

Please sign in to comment.