Skip to content

Commit 14e1861

Browse files
committed
chore: add some comments
1 parent 371078c commit 14e1861

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/mount.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,20 @@ export function mount(
425425

426426
// mount the app!
427427
const vm = app.mount(el)
428-
const appRef = vm.$refs[MOUNT_COMPONENT_REF] as ComponentPublicInstance
429428

429+
// Ingore Avoid app logic that relies on enumerating keys on a component instance... warning
430430
const warnSave = console.warn
431431
console.warn = () => {}
432+
433+
// get `vm`.
434+
// for some unknown reason, getting the `vm` for components using `<script setup>`
435+
// as of Vue 3.0.3 works differently.
436+
// if `appRef` has keys, use that (vm always has keys like $el, $props etc).
437+
// if not, use the return value from app.mount.
438+
const appRef = vm.$refs[MOUNT_COMPONENT_REF] as ComponentPublicInstance
432439
const $vm = Reflect.ownKeys(appRef).length ? appRef : vm
433440
console.warn = warnSave
441+
434442
return createWrapper(app, $vm, setProps)
435443
}
436444

tests/components/ScriptSetup.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
// imported components are also directly usable in template
33
import { ref } from 'vue'
4+
import Hello from './Hello.vue'
45
56
// write Composition API code just like in a normal setup()
67
// but no need to manually return everything
@@ -10,4 +11,5 @@ const inc = () => { count.value++ }
1011

1112
<template>
1213
<button @click="inc">{{ count }}</button>
14+
<Hello />
1315
</template>

tests/features/sfc.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ describe('sfc', () => {
1111
// rfc: https://github.com/vuejs/rfcs/pull/228
1212
it('works with <script setup> (as of Vue 3.0.3)', async () => {
1313
const wrapper = mount(ScriptSetup)
14+
expect(wrapper.findComponent(Hello).exists()).toBe(true)
15+
1416
await wrapper.find('button').trigger('click')
1517
expect(wrapper.html()).toContain('1')
1618
})

0 commit comments

Comments
 (0)