1
1
describe ( 'Batcher' , function ( ) {
2
2
3
- var batcher = require ( 'vue/src/batcher' ) ,
3
+ var Batcher = require ( 'vue/src/batcher' ) ,
4
+ batcher = new Batcher ( ) ,
4
5
nextTick = require ( 'vue/src/utils' ) . nextTick
5
6
6
7
var updateCount = 0
7
- function mockBinding ( id , middleware ) {
8
+ function mockJob ( id , middleware ) {
8
9
return {
9
10
id : id ,
10
- _update : function ( ) {
11
+ execute : function ( ) {
11
12
updateCount ++
12
13
this . updated = true
13
14
if ( middleware ) middleware ( )
14
15
}
15
16
}
16
17
}
17
18
18
- it ( 'should queue bindings to be updated on nextTick' , function ( done ) {
19
+ it ( 'should push bindings to be updated on nextTick' , function ( done ) {
19
20
20
21
updateCount = 0
21
- var b1 = mockBinding ( 1 ) ,
22
- b2 = mockBinding ( 2 )
23
- batcher . queue ( b1 )
24
- batcher . queue ( b2 )
22
+ var b1 = mockJob ( 1 ) ,
23
+ b2 = mockJob ( 2 )
24
+ batcher . push ( b1 )
25
+ batcher . push ( b2 )
25
26
assert . strictEqual ( updateCount , 0 )
26
27
assert . notOk ( b1 . updated )
27
28
assert . notOk ( b2 . updated )
@@ -35,13 +36,13 @@ describe('Batcher', function () {
35
36
36
37
} )
37
38
38
- it ( 'should not queue dupicate bindings' , function ( done ) {
39
+ it ( 'should not push dupicate bindings' , function ( done ) {
39
40
40
41
updateCount = 0
41
- var b1 = mockBinding ( 1 ) ,
42
- b2 = mockBinding ( 1 )
43
- batcher . queue ( b1 )
44
- batcher . queue ( b2 )
42
+ var b1 = mockJob ( 1 ) ,
43
+ b2 = mockJob ( 1 )
44
+ batcher . push ( b1 )
45
+ batcher . push ( b2 )
45
46
46
47
nextTick ( function ( ) {
47
48
assert . strictEqual ( updateCount , 1 )
@@ -52,14 +53,14 @@ describe('Batcher', function () {
52
53
53
54
} )
54
55
55
- it ( 'should queue dependency bidnings triggered during flush' , function ( done ) {
56
+ it ( 'should push dependency bidnings triggered during flush' , function ( done ) {
56
57
57
58
updateCount = 0
58
- var b1 = mockBinding ( 1 ) ,
59
- b2 = mockBinding ( 2 , function ( ) {
60
- batcher . queue ( b1 )
59
+ var b1 = mockJob ( 1 ) ,
60
+ b2 = mockJob ( 2 , function ( ) {
61
+ batcher . push ( b1 )
61
62
} )
62
- batcher . queue ( b2 )
63
+ batcher . push ( b2 )
63
64
64
65
nextTick ( function ( ) {
65
66
assert . strictEqual ( updateCount , 2 )
@@ -70,4 +71,39 @@ describe('Batcher', function () {
70
71
71
72
} )
72
73
74
+ it ( 'should allow overriding jobs with same ID' , function ( done ) {
75
+
76
+ updateCount = 0
77
+ var b1 = mockJob ( 1 ) ,
78
+ b2 = mockJob ( 1 )
79
+
80
+ b2 . override = true
81
+ batcher . push ( b1 )
82
+ batcher . push ( b2 )
83
+
84
+ nextTick ( function ( ) {
85
+ assert . strictEqual ( updateCount , 1 )
86
+ assert . ok ( b1 . cancelled )
87
+ assert . notOk ( b1 . updated )
88
+ assert . ok ( b2 . updated )
89
+ done ( )
90
+ } )
91
+
92
+ } )
93
+
94
+ it ( 'should execute the _preFlush hook' , function ( done ) {
95
+
96
+ var executed = false
97
+ batcher . _preFlush = function ( ) {
98
+ executed = true
99
+ }
100
+ batcher . push ( mockJob ( 1 ) )
101
+
102
+ nextTick ( function ( ) {
103
+ assert . ok ( executed )
104
+ done ( )
105
+ } )
106
+
107
+ } )
108
+
73
109
} )
0 commit comments