Skip to content

Commit ac8fd36

Browse files
Test for shouldUpdate with lazy async computed values
1 parent e9359d4 commit ac8fd36

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/index.js

+59
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,62 @@ test("Underscore prefixes work (issue #33)", t => {
600600
t.equal(val, 2)
601601
})
602602
})
603+
604+
test("shouldUpdate works with lazy", t => {
605+
t.plan(8)
606+
const vm = new Vue({
607+
data: {
608+
a: 0,
609+
x: true,
610+
y: false,
611+
},
612+
asyncComputed: {
613+
b: {
614+
lazy: true,
615+
get () {
616+
return Promise.resolve(this.a)
617+
},
618+
shouldUpdate () {
619+
return this.x
620+
}
621+
},
622+
c: {
623+
lazy: true,
624+
get () {
625+
return Promise.resolve(this.a)
626+
},
627+
shouldUpdate () {
628+
return this.y
629+
}
630+
}
631+
}
632+
})
633+
634+
Vue.nextTick(() => {
635+
t.equal(vm.b, null)
636+
t.equal(vm.c, null)
637+
Vue.nextTick(() => {
638+
Vue.nextTick(() => {
639+
t.equal(vm.b, 0)
640+
t.equal(vm.c, null)
641+
vm.a++
642+
Vue.nextTick(() => {
643+
Vue.nextTick(() => {
644+
t.equal(vm.b, 1)
645+
t.equal(vm.c, null)
646+
vm.x = false
647+
vm.y = true
648+
vm.a++
649+
Vue.nextTick(() => {
650+
Vue.nextTick(() => {
651+
t.equal(vm.b, 1)
652+
t.equal(vm.c, 2)
653+
})
654+
})
655+
})
656+
})
657+
})
658+
})
659+
})
660+
})
661+

0 commit comments

Comments
 (0)