Skip to content

Commit e4151b0

Browse files
committed
feat(update): run watchers in update
closes #283
1 parent 7db74a3 commit e4151b0

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/wrappers/vue-wrapper.js

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ function update () {
1515
const vnodes = this._render()
1616
this._update(vnodes)
1717
this.$children.forEach(child => update.call(child))
18+
this._watchers.forEach(watcher => {
19+
watcher.run()
20+
})
1821
}
1922

2023
export default class VueWrapper extends Wrapper implements BaseWrapper {

src/wrappers/wrapper.js

-17
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,6 @@ export default class Wrapper implements BaseWrapper {
340340
this.vm.$set(this.vm, [key], data[key])
341341
})
342342

343-
Object.keys(data).forEach((key) => {
344-
// $FlowIgnore : Problem with possibly null this.vm
345-
this.vm._watchers.forEach((watcher) => {
346-
if (watcher.expression === key) { watcher.run() }
347-
})
348-
})
349-
350343
this.update()
351344
}
352345

@@ -393,10 +386,6 @@ export default class Wrapper implements BaseWrapper {
393386
}
394387
})
395388
}
396-
// $FlowIgnore
397-
this.vm._watchers.forEach((watcher) => {
398-
if (watcher.expression === key) { watcher.run() }
399-
})
400389
})
401390
this.update()
402391
}
@@ -435,12 +424,6 @@ export default class Wrapper implements BaseWrapper {
435424
}
436425
})
437426

438-
Object.keys(data).forEach((key) => {
439-
// $FlowIgnore : Problem with possibly null this.vm
440-
this.vm._watchers.forEach((watcher) => {
441-
if (watcher.expression === key) { watcher.run() }
442-
})
443-
})
444427
this.update()
445428
// $FlowIgnore : Problem with possibly null this.vm
446429
this.vnode = this.vm._vnode

test/unit/specs/mount/Wrapper/update.spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,36 @@ describe('update', () => {
3838
expect(innerEl.hasClass('is-on')).to.equal(true)
3939
})
4040

41+
it('runs watchers', () => {
42+
const TestComponent = {
43+
template: `
44+
<div>
45+
<input v-model="text" />
46+
<button v-if="showButton">Submit</button>
47+
</div>
48+
`,
49+
data () {
50+
return {
51+
text: '',
52+
showButton: false
53+
}
54+
},
55+
56+
watch: {
57+
text () {
58+
this.showButton = true
59+
}
60+
}
61+
}
62+
const wrapper = mount(TestComponent)
63+
64+
wrapper.find('input').element.value = 'Value'
65+
wrapper.find('input').trigger('input')
66+
67+
expect(wrapper.vm.showButton).to.equal(true)
68+
expect(wrapper.find('button').exists()).to.equal(true)
69+
})
70+
4171
it('causes vm to re render, and retain slots', () => {
4272
const compiled = compileToFunctions('<div><slot></slot></div>')
4373
const wrapper = mount(compiled, { slots: { default: [compileToFunctions('<div class="test-div" />')] }})

0 commit comments

Comments
 (0)