Skip to content

Commit d41adb2

Browse files
committed
tests: add a regression tests for setData and watch
1 parent b7bb435 commit d41adb2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/setData.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,41 @@ describe('setData', () => {
1616
expect(wrapper.html()).toContain('qux')
1717
})
1818

19+
// This was a problem in V1
20+
// See: https://github.com/vuejs/vue-test-utils/issues/1756
21+
// Making sure it does not regress here.
22+
it('triggers a watcher', async () => {
23+
const Comp = {
24+
template: `<div />`,
25+
data() {
26+
return {
27+
myObject: {
28+
key: 'value'
29+
},
30+
watchCounter: 0
31+
}
32+
},
33+
watch: {
34+
myObject: {
35+
immediate: true,
36+
handler() {
37+
this.watchCounter += 1
38+
}
39+
}
40+
}
41+
}
42+
43+
const initial = 'value'
44+
const expected = 'something else'
45+
const wrapper = mount(Comp)
46+
expect(wrapper.vm.myObject.key).toBe(initial)
47+
expect(wrapper.vm.watchCounter).toBe(1)
48+
49+
await wrapper.setData({ myObject: { key: expected } })
50+
expect(wrapper.vm.myObject.key).toEqual(expected)
51+
expect(wrapper.vm.watchCounter).toBe(2)
52+
})
53+
1954
it('causes nested nodes to re-render', async () => {
2055
const Component = {
2156
template: `<div><div v-if="show" id="show">Show</div></div>`,

0 commit comments

Comments
 (0)