feat(module): add support for vue using unplugin (#2416)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Daniel Roe
2024-10-25 16:15:26 +01:00
committed by GitHub
parent 50c6bf0092
commit d4a943e631
97 changed files with 18948 additions and 117 deletions

34
test/utils/mount.ts Normal file
View File

@@ -0,0 +1,34 @@
import { mount } from '@vue/test-utils'
import { createRouter, createWebHistory } from 'vue-router'
import { defu } from 'defu'
import type { SetupContext } from 'vue'
const router = createRouter({
history: createWebHistory(),
routes: [{ path: '/', component: { template: '<div>Home</div>' } }]
})
export function mountSuspended(...args: Parameters<typeof mount>) {
let setupState = {}
const comp = args[0] as any
if (comp.setup) {
const originalSetup = comp.setup
comp.setup = function (props: Record<string, any>, ctx: SetupContext) {
setupState = originalSetup.call(this, props, ctx)
return setupState
}
}
const wrapper = mount(args[0], defu({}, args[1], {
global: {
stubs: {
ClientOnly: { template: '<slot />' }
},
plugins: [router]
}
}))
// @ts-expect-error - setupState does not exist in type
wrapper.setupState = setupState
return wrapper
}

8
test/utils/setup.ts Normal file
View File

@@ -0,0 +1,8 @@
// @ts-expect-error incomplete implementation
window.IntersectionObserver = class IntersectionObserver {
// eslint-disable-next-line
constructor() {}
observe() {}
unobserve() {}
disconnect() {}
}