-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatcher_spec.js
121 lines (114 loc) · 2.42 KB
/
batcher_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var config = require('src/config')
var batcher = require('src/batcher')
var nextTick = require('src/util').nextTick
describe('Batcher', function () {
var spy
beforeEach(function () {
spy = jasmine.createSpy('batcher')
})
it('pushWatcher', function (done) {
batcher.pushWatcher({
run: spy
})
nextTick(function () {
expect(spy.calls.count()).toBe(1)
done()
})
})
it('dedup', function (done) {
batcher.pushWatcher({
id: 1,
run: spy
})
batcher.pushWatcher({
id: 1,
run: spy
})
nextTick(function () {
expect(spy.calls.count()).toBe(1)
done()
})
})
it('allow diplicate when flushing', function (done) {
var job = {
id: 1,
run: spy
}
batcher.pushWatcher(job)
batcher.pushWatcher({
id: 2,
run: function () {
batcher.pushWatcher(job)
}
})
nextTick(function () {
expect(spy.calls.count()).toBe(2)
done()
})
})
it('calls user watchers after directive updates', function (done) {
var vals = []
function run () {
vals.push(this.id)
}
batcher.pushWatcher({
id: 2,
user: true,
run: function () {
run.call(this)
// user watcher triggering another directive update!
batcher.pushWatcher({
id: 3,
run: run
})
}
})
batcher.pushWatcher({
id: 1,
run: run
})
nextTick(function () {
expect(vals[0]).toBe(1)
expect(vals[1]).toBe(2)
expect(vals[2]).toBe(3)
done()
})
})
it('warn against infinite update loops', function (done) {
var count = 0
var job = {
id: 1,
run: function () {
count++
batcher.pushWatcher(job)
}
}
batcher.pushWatcher(job)
nextTick(function () {
expect(count).toBe(config._maxUpdateCount + 1)
expect('infinite update loop').toHaveBeenWarned()
done()
})
})
it('should call newly pushed watcher after current watcher is done', function (done) {
var callOrder = []
batcher.pushWatcher({
id: 1,
user: true,
run: function () {
callOrder.push(1)
batcher.pushWatcher({
id: 2,
run: function () {
callOrder.push(3)
}
})
callOrder.push(2)
}
})
nextTick(function () {
expect(callOrder.join()).toBe('1,2,3')
done()
})
})
})