11describe ( 'Batcher' , function ( ) {
22
3- var batcher = require ( 'vue/src/batcher' ) ,
3+ var Batcher = require ( 'vue/src/batcher' ) ,
4+ batcher = new Batcher ( ) ,
45 nextTick = require ( 'vue/src/utils' ) . nextTick
56
67 var updateCount = 0
7- function mockBinding ( id , middleware ) {
8+ function mockJob ( id , middleware ) {
89 return {
910 id : id ,
10- _update : function ( ) {
11+ execute : function ( ) {
1112 updateCount ++
1213 this . updated = true
1314 if ( middleware ) middleware ( )
1415 }
1516 }
1617 }
1718
18- it ( 'should queue bindings to be updated on nextTick' , function ( done ) {
19+ it ( 'should push bindings to be updated on nextTick' , function ( done ) {
1920
2021 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 )
2526 assert . strictEqual ( updateCount , 0 )
2627 assert . notOk ( b1 . updated )
2728 assert . notOk ( b2 . updated )
@@ -35,13 +36,13 @@ describe('Batcher', function () {
3536
3637 } )
3738
38- it ( 'should not queue dupicate bindings' , function ( done ) {
39+ it ( 'should not push dupicate bindings' , function ( done ) {
3940
4041 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 )
4546
4647 nextTick ( function ( ) {
4748 assert . strictEqual ( updateCount , 1 )
@@ -52,14 +53,14 @@ describe('Batcher', function () {
5253
5354 } )
5455
55- it ( 'should queue dependency bidnings triggered during flush' , function ( done ) {
56+ it ( 'should push dependency bidnings triggered during flush' , function ( done ) {
5657
5758 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 )
6162 } )
62- batcher . queue ( b2 )
63+ batcher . push ( b2 )
6364
6465 nextTick ( function ( ) {
6566 assert . strictEqual ( updateCount , 2 )
@@ -70,4 +71,39 @@ describe('Batcher', function () {
7071
7172 } )
7273
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+
73109} )
0 commit comments