File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -425,12 +425,20 @@ export function mount(
425
425
426
426
// mount the app!
427
427
const vm = app . mount ( el )
428
- const appRef = vm . $refs [ MOUNT_COMPONENT_REF ] as ComponentPublicInstance
429
428
429
+ // Ingore Avoid app logic that relies on enumerating keys on a component instance... warning
430
430
const warnSave = console . warn
431
431
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
432
439
const $vm = Reflect . ownKeys ( appRef ) . length ? appRef : vm
433
440
console . warn = warnSave
441
+
434
442
return createWrapper ( app , $vm , setProps )
435
443
}
436
444
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
2
// imported components are also directly usable in template
3
3
import { ref } from ' vue'
4
+ import Hello from ' ./Hello.vue'
4
5
5
6
// write Composition API code just like in a normal setup()
6
7
// but no need to manually return everything
@@ -10,4 +11,5 @@ const inc = () => { count.value++ }
10
11
11
12
<template >
12
13
<button @click =" inc" >{{ count }}</button >
14
+ <Hello />
13
15
</template >
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ describe('sfc', () => {
11
11
// rfc: https://github.com/vuejs/rfcs/pull/228
12
12
it ( 'works with <script setup> (as of Vue 3.0.3)' , async ( ) => {
13
13
const wrapper = mount ( ScriptSetup )
14
+ expect ( wrapper . findComponent ( Hello ) . exists ( ) ) . toBe ( true )
15
+
14
16
await wrapper . find ( 'button' ) . trigger ( 'click' )
15
17
expect ( wrapper . html ( ) ) . toContain ( '1' )
16
18
} )
You can’t perform that action at this time.
0 commit comments