Skip to content

Commit 62aca6d

Browse files
authored
Merge pull request #64 from cexbrayat/fix/vm-type
fix: vm should be the vm of the tested component
2 parents 26703e1 + 417ae50 commit 62aca6d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/vue-wrapper.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export class VueWrapper implements WrapperAPI {
1919
) {
2020
this.__vm = vm
2121
this.__setProps = setProps
22-
this.componentVM = this.vm.$refs['VTU_COMPONENT'] as ComponentPublicInstance
22+
this.componentVM = this.__vm.$refs[
23+
'VTU_COMPONENT'
24+
] as ComponentPublicInstance
2325
this.__emitted = events
2426
}
2527

@@ -42,7 +44,7 @@ export class VueWrapper implements WrapperAPI {
4244
}
4345

4446
get vm(): ComponentPublicInstance {
45-
return this.__vm
47+
return this.componentVM
4648
}
4749

4850
classes(className?: string) {

tests/vm.spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { defineComponent, ref } from 'vue'
2+
3+
import { mount } from '../src'
4+
5+
describe('vm', () => {
6+
it('returns the component vm', () => {
7+
const Component = defineComponent({
8+
template: '<div>{{ msg }}</div>',
9+
setup() {
10+
const msg = 'hello'
11+
const isEnabled = ref(true)
12+
return { msg, isEnabled }
13+
}
14+
})
15+
16+
const wrapper = mount(Component)
17+
18+
expect((wrapper.vm as any).msg).toBe('hello')
19+
expect((wrapper.vm as any).isEnabled).toBe(true)
20+
})
21+
})

0 commit comments

Comments
 (0)