Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(mount): simplify mount operation #1844

Merged
merged 1 commit into from Nov 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/mount.ts
Expand Up @@ -25,7 +25,8 @@ import {
ComponentOptions,
ConcreteComponent,
Prop,
transformVNodeArgs
transformVNodeArgs,
ref
} from 'vue'

import { MountingOptions, Slot } from './types'
Expand Down Expand Up @@ -432,9 +433,15 @@ export function mount(
component.components = { ...component.components, ...global.components }
}

const componentRef = ref(null)
// create the wrapper component
const Parent = defineComponent({
name: 'VTU_ROOT',
setup() {
return {
[MOUNT_COMPONENT_REF]: componentRef
}
},
render() {
return h(component as ComponentOptions, { ...props, ...refs }, slots)
}
Expand Down Expand Up @@ -561,17 +568,12 @@ export function mount(
// mount the app!
const vm = app.mount(el)

// Ignore "Avoid app logic that relies on enumerating keys on a component instance..." warning
const warnSave = console.warn
console.warn = () => {}

const appRef = vm.$refs[MOUNT_COMPONENT_REF] as ComponentPublicInstance
const appRef = componentRef.value! as ComponentPublicInstance
// we add `hasOwnProperty` so Jest can spy on the proxied vm without throwing
// note that this is not necessary with Jest v27+ or Vitest, but is kept for compatibility with older Jest versions
appRef.hasOwnProperty = (property) => {
return Reflect.has(appRef, property)
}
console.warn = warnSave
const wrapper = createVueWrapper(app, appRef, setProps)
trackInstance(wrapper)
return wrapper
Expand Down