Skip to content

Feature request: Support wrapper option in mount() to wrap component under test #2903

Description

@Jungzl

Is your feature request related to a problem? Please describe.

Currently, when testing Vue components that depend on context providers (e.g., <Suspense>, <RouterView>, pinia stores, or custom provide/inject wrappers), users must manually create a wrapper component via defineComponent + h() to wrap the component under test:

const Wrapped = defineComponent({
  render() {
    return h(MyProvider, null, { default: () => h(Component) })
  }
})
mount(Wrapped)

This is boilerplate-heavy and inconsistent with the ergonomics of other framework testing tools that support a native wrapper pattern.

Describe the solution you'd like

Add a wrapper option to mount() that accepts either a Vue component or a render function:

// Form 1: component object
mount(Component, {
  wrapper: MyProvider,
})

// Form 2: render function — allows passing props to the wrapper
mount(Component, {
  wrapper: ({ default: defaultSlot }) =>
    h(MyProvider, { theme: 'dark' }, { default: defaultSlot }),
})

When a component object is provided, it is rendered with the target component as its default slot:

// Equivalent to:
h(MyProvider, null, { default: () => h(Component) })

When a render function is provided, it receives the target component's default slot and returns a VNode — giving full control over wrapper props and slot composition.

Describe alternatives you've considered

No response

Additional context

This pattern is already well-established in other testing ecosystems:

Having this in VTU would directly enable vitest-browser-vue to expose the same wrapper option without needing to construct a wrapper component inline via defineComponent + h(). Since vitest-browser-vue's render() delegates to mount(), a VTU-level wrapper would be a natural fit — just pass through the option and let VTU handle the rest.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions