Skip to content

Commit 751b0c8

Browse files
committed
fix watcher tests
1 parent 9b94176 commit 751b0c8

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

test/unit/modules/observer/watcher.spec.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,15 @@ describe('Watcher', () => {
6161

6262
it('path containing $data', done => {
6363
const watcher = new Watcher(vm, '$data.b.c', spy)
64-
expect(watcher.value).toBeUndefined()
64+
expect(watcher.value).toBe(2)
6565
vm.b = { c: 3 }
6666
waitForUpdate(() => {
67-
expect(watcher.value).toBeUndefined()
68-
expect(spy).not.toHaveBeenCalledWith(3, 2)
69-
vm.$data = { b: { c: 4 }}
67+
expect(watcher.value).toBe(3)
68+
expect(spy).toHaveBeenCalledWith(3, 2)
69+
vm.$data.b.c = 4
7070
}).then(() => {
71-
expect(watcher.value).toBeUndefined()
72-
expect(spy).not.toHaveBeenCalledWith(4, 3)
73-
}).then(done)
74-
})
75-
76-
it('not watching $data', done => {
77-
const oldData = vm.$data
78-
const watcher = new Watcher(vm, '$data', spy)
79-
expect(watcher.value).toBeUndefined()
80-
const newData = {}
81-
vm.$data = newData
82-
waitForUpdate(() => {
83-
expect(spy).not.toHaveBeenCalledWith(newData, oldData)
84-
expect(watcher.value).toBeUndefined()
71+
expect(watcher.value).toBe(4)
72+
expect(spy).toHaveBeenCalledWith(4, 3)
8573
}).then(done)
8674
})
8775

@@ -105,6 +93,16 @@ describe('Watcher', () => {
10593
}).then(done)
10694
})
10795

96+
it('deep watch $data', done => {
97+
new Watcher(vm, '$data', spy, {
98+
deep: true
99+
})
100+
vm.b.c = 3
101+
waitForUpdate(() => {
102+
expect(spy).toHaveBeenCalledWith(vm.$data, vm.$data)
103+
}).then(done)
104+
})
105+
108106
it('deep watch with circular references', done => {
109107
new Watcher(vm, 'b', spy, {
110108
deep: true

0 commit comments

Comments
 (0)