-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: vm should be the vm of the tested component
It currently returns the vm of the parent element. With this commit, it now returns the vm of the tested element. The types have also been tweaked to avoid the need of casting like `(wrapper.vm as any).msg`.
- Loading branch information
Showing
3 changed files
with
46 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { defineComponent, ref } from 'vue' | ||
|
||
import { mount } from '../src' | ||
|
||
describe('vm', () => { | ||
it('returns the component vm', () => { | ||
const Component = defineComponent({ | ||
template: '<div>{{ msg }}</div>', | ||
setup() { | ||
const msg = 'hello' | ||
const isEnabled = ref(true) | ||
const toggle = () => (isEnabled.value = !isEnabled.value) | ||
return { msg, isEnabled, toggle } | ||
} | ||
}) | ||
|
||
const wrapper = mount(Component) | ||
|
||
expect(wrapper.vm.msg).toBe('hello') | ||
expect(wrapper.vm.isEnabled).toBe(true) | ||
|
||
wrapper.vm.toggle() | ||
|
||
expect(wrapper.vm.isEnabled).toBe(false) | ||
}) | ||
}) |