import { type ComponentMountingOptions, mount } from '@vue/test-utils' import { createPinia } from 'pinia' import type { Component } from 'vue' type MountGlobalOptions = NonNullable['global']> type MountDirectives = NonNullable type MountPlugins = NonNullable type MountStubs = NonNullable const defaultDirectives: MountDirectives = {} const defaultStubs: MountStubs = {} export function createWrapperFor( component: T, options: ComponentMountingOptions = {}, mountingMethod: typeof mount = mount, ) { const mountFn = mountingMethod ?? mount const defaultPlugins: MountPlugins = [createPinia()] const globalPlugins = options.global?.plugins ? [...defaultPlugins, ...options.global.plugins] : defaultPlugins const mergedDirectives: MountDirectives = { ...defaultDirectives, ...options.global?.directives, } const mergedStubs: MountStubs = { ...defaultStubs, ...options.global?.stubs, } const mergedOptions: ComponentMountingOptions = { ...options, global: { ...options.global, directives: mergedDirectives, plugins: globalPlugins, stubs: mergedStubs, }, } return mountFn(component, mergedOptions) }