mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
feat(module): add support for vue using unplugin (#2416)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
34
test/utils/mount.ts
Normal file
34
test/utils/mount.ts
Normal 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
8
test/utils/setup.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// @ts-expect-error incomplete implementation
|
||||
window.IntersectionObserver = class IntersectionObserver {
|
||||
// eslint-disable-next-line
|
||||
constructor() {}
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
}
|
||||
Reference in New Issue
Block a user