From 417ae5042fd47fc6497505ad4db43b28d6a85f2a Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Mon, 13 Apr 2020 17:30:47 +0200 Subject: [PATCH] fix: vm should be the vm of the tested component --- src/vue-wrapper.ts | 6 ++++-- tests/vm.spec.ts | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/vm.spec.ts diff --git a/src/vue-wrapper.ts b/src/vue-wrapper.ts index e0f28b863..73960d350 100644 --- a/src/vue-wrapper.ts +++ b/src/vue-wrapper.ts @@ -19,7 +19,9 @@ export class VueWrapper implements WrapperAPI { ) { this.__vm = vm this.__setProps = setProps - this.componentVM = this.vm.$refs['VTU_COMPONENT'] as ComponentPublicInstance + this.componentVM = this.__vm.$refs[ + 'VTU_COMPONENT' + ] as ComponentPublicInstance this.__emitted = events } @@ -42,7 +44,7 @@ export class VueWrapper implements WrapperAPI { } get vm(): ComponentPublicInstance { - return this.__vm + return this.componentVM } classes(className?: string) { diff --git a/tests/vm.spec.ts b/tests/vm.spec.ts new file mode 100644 index 000000000..0d909d5c6 --- /dev/null +++ b/tests/vm.spec.ts @@ -0,0 +1,21 @@ +import { defineComponent, ref } from 'vue' + +import { mount } from '../src' + +describe('vm', () => { + it('returns the component vm', () => { + const Component = defineComponent({ + template: '
{{ msg }}
', + setup() { + const msg = 'hello' + const isEnabled = ref(true) + return { msg, isEnabled } + } + }) + + const wrapper = mount(Component) + + expect((wrapper.vm as any).msg).toBe('hello') + expect((wrapper.vm as any).isEnabled).toBe(true) + }) +})