Skip to content

Commit

Permalink
chore(mount): simplify mount operation
Browse files Browse the repository at this point in the history
* do not use ugly console.warn hack
  • Loading branch information
xanf committed Nov 3, 2022
1 parent b881c10 commit 5254f7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 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 @@ -565,7 +572,7 @@ export function mount(
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) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/shallowMount.spec.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { defineAsyncComponent, defineComponent } from 'vue'
import { defineAsyncComponent, defineComponent, onMounted } from 'vue'
import { mount, shallowMount, VueWrapper } from '../src'
import ComponentWithChildren from './components/ComponentWithChildren.vue'
import ScriptSetupWithChildren from './components/ScriptSetupWithChildren.vue'
Expand Down

0 comments on commit 5254f7b

Please sign in to comment.