From cebc0e0ae6a86be3fab5a03e6228224d0dbabe8d Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Thu, 3 Nov 2022 09:04:48 +0200 Subject: [PATCH] chore(mount): simplify mount operation (#1844) * do not use ugly console.warn hack --- src/mount.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index 00efa87b3..58d10d0e6 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -25,7 +25,8 @@ import { ComponentOptions, ConcreteComponent, Prop, - transformVNodeArgs + transformVNodeArgs, + ref } from 'vue' import { MountingOptions, Slot } from './types' @@ -438,9 +439,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) } @@ -570,17 +577,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