Skip to content

Commit 0494f78

Browse files
committed
Add tests for default values in watch & computed
1 parent 5afdd4f commit 0494f78

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/index.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ test("Multiple asyncComputed objects are handled the same as normal computed pro
221221
})
222222

223223
test("Async computed values can have defaults", t => {
224-
t.plan(6)
224+
t.plan(8)
225225
const vm = new Vue({
226226
asyncComputed: {
227227
x: {
@@ -238,9 +238,27 @@ test("Async computed values can have defaults", t => {
238238
return Promise.resolve(true)
239239
}
240240
}
241-
}
241+
},
242+
watch: {
243+
x: {
244+
deep: true,
245+
immediate: true,
246+
handler (newValue, oldValue) {
247+
if (oldValue === undefined) {
248+
t.equal(newValue, false, 'watch: x should default to false')
249+
}
250+
}
251+
},
252+
},
253+
computed: {
254+
computedFromX: function () {
255+
t.equal(this.x, false, 'computed: x should default to false')
256+
return this.x
257+
},
258+
},
242259
})
243-
t.equal(vm.x, false, 'x should default to true')
260+
const computed = vm.computedFromX// Force computed execution
261+
t.equal(vm.x, false, 'x should default to false')
244262
t.equal(vm.y, null, 'y doesn\'t have a default')
245263
t.equal(vm.z, null, 'z doesn\'t have a default despite being defined with an object')
246264
Vue.nextTick(() => {

0 commit comments

Comments
 (0)