import { mount } from '@vue/test-utils' import { createPinia, setActivePinia } from 'pinia' // Smoke-test helper. Vuetify components are left unresolved (Vue 3 renders // unknown elements with their slot children, so text content is still // present and nothing throws), which avoids standing up the whole Vuetify // plugin in happy-dom. RouterLink is the one import that needs a router, so // it's stubbed with a slot-rendering anchor. export function freshPinia () { const pinia = createPinia() setActivePinia(pinia) return pinia } // `stubs` is merged over the defaults. Needed whenever the component under // test puts content in a NAMED slot of a Vuetify component: leaving those // unresolved renders default-slot children only, so a named slot (v-tooltip's // `#activator`, say) silently renders nothing and assertions find an empty // wrapper rather than failing loudly. export function mountComponent (Component, { props = {}, pinia, stubs = {} } = {}) { return mount(Component, { props, global: { plugins: pinia ? [pinia] : [], stubs: { RouterLink: { template: '' }, ...stubs }, }, }) } // Renders both halves of a v-tooltip: the activator (the thing the operator // actually sees) and the tip body. `props` is passed as an empty object so the // activator's `v-bind="tipProps"` binds cleanly. export const VTooltipStub = { name: 'VTooltip', template: '
', } // Mount with a fresh pinia and the store already seeded, for components that // read store state during render. Without it, the seeding has to be inlined // between createPinia and mount in every spec — the same copy-paste that issue // #3109 tracks for the backend row factories. export function mountWithStore (Component, seed, opts = {}) { const pinia = freshPinia() seed() return mountComponent(Component, { ...opts, pinia }) }