@@ -14,12 +14,12 @@ describe('carousel', function() {
14
14
} ) ) ;
15
15
beforeEach ( module ( 'template/carousel/carousel.html' , 'template/carousel/slide.html' ) ) ;
16
16
17
- var $rootScope , $compile , $controller , $timeout ;
18
- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$controller_ , _$timeout_ ) {
17
+ var $rootScope , $compile , $controller , $interval ;
18
+ beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$controller_ , _$interval_ ) {
19
19
$rootScope = _$rootScope_ ;
20
20
$compile = _$compile_ ;
21
21
$controller = _$controller_ ;
22
- $timeout = _$timeout_ ;
22
+ $interval = _$interval_ ;
23
23
} ) ) ;
24
24
25
25
describe ( 'basics' , function ( ) {
@@ -148,16 +148,18 @@ describe('carousel', function() {
148
148
149
149
it ( 'shouldnt go forward if interval is NaN or negative' , function ( ) {
150
150
testSlideActive ( 0 ) ;
151
+ var previousInterval = scope . interval ;
151
152
scope . $apply ( 'interval = -1' ) ;
152
- //no timeout to flush, interval watch doesn't make a new one when interval is invalid
153
+ $ interval. flush ( previousInterval ) ;
153
154
testSlideActive ( 0 ) ;
154
155
scope . $apply ( 'interval = 1000' ) ;
155
- $timeout . flush ( ) ;
156
+ $interval . flush ( 1000 ) ;
156
157
testSlideActive ( 1 ) ;
157
158
scope . $apply ( 'interval = false' ) ;
159
+ $interval . flush ( 1000 ) ;
158
160
testSlideActive ( 1 ) ;
159
161
scope . $apply ( 'interval = 1000' ) ;
160
- $timeout . flush ( ) ;
162
+ $interval . flush ( 1000 ) ;
161
163
testSlideActive ( 2 ) ;
162
164
} ) ;
163
165
@@ -182,34 +184,35 @@ describe('carousel', function() {
182
184
183
185
it ( 'should be playing by default and cycle through slides' , function ( ) {
184
186
testSlideActive ( 0 ) ;
185
- $timeout . flush ( ) ;
187
+ $interval . flush ( scope . interval ) ;
186
188
testSlideActive ( 1 ) ;
187
- $timeout . flush ( ) ;
189
+ $interval . flush ( scope . interval ) ;
188
190
testSlideActive ( 2 ) ;
189
- $timeout . flush ( ) ;
191
+ $interval . flush ( scope . interval ) ;
190
192
testSlideActive ( 0 ) ;
191
193
} ) ;
192
194
193
195
it ( 'should pause and play on mouseover' , function ( ) {
194
196
testSlideActive ( 0 ) ;
195
- $timeout . flush ( ) ;
197
+ $interval . flush ( scope . interval ) ;
196
198
testSlideActive ( 1 ) ;
197
199
elm . trigger ( 'mouseenter' ) ;
198
- expect ( $timeout . flush ) . toThrow ( ) ; //pause should cancel current timeout
200
+ testSlideActive ( 1 ) ;
201
+ $interval . flush ( scope . interval ) ;
199
202
testSlideActive ( 1 ) ;
200
203
elm . trigger ( 'mouseleave' ) ;
201
- $timeout . flush ( ) ;
204
+ $interval . flush ( scope . interval ) ;
202
205
testSlideActive ( 2 ) ;
203
206
} ) ;
204
207
205
208
it ( 'should not pause on mouseover if noPause' , function ( ) {
206
209
scope . $apply ( 'nopause = true' ) ;
207
210
testSlideActive ( 0 ) ;
208
211
elm . trigger ( 'mouseenter' ) ;
209
- $timeout . flush ( ) ;
212
+ $interval . flush ( scope . interval ) ;
210
213
testSlideActive ( 1 ) ;
211
214
elm . trigger ( 'mouseleave' ) ;
212
- $timeout . flush ( ) ;
215
+ $interval . flush ( scope . interval ) ;
213
216
testSlideActive ( 2 ) ;
214
217
} ) ;
215
218
@@ -219,7 +222,7 @@ describe('carousel', function() {
219
222
scope . $apply ( 'slides.splice(0,1)' ) ;
220
223
expect ( elm . find ( 'div.item' ) . length ) . toBe ( 2 ) ;
221
224
testSlideActive ( 1 ) ;
222
- $timeout . flush ( ) ;
225
+ $interval . flush ( scope . interval ) ;
223
226
testSlideActive ( 0 ) ;
224
227
scope . $apply ( 'slides.splice(1,1)' ) ;
225
228
expect ( elm . find ( 'div.item' ) . length ) . toBe ( 1 ) ;
@@ -253,14 +256,15 @@ describe('carousel', function() {
253
256
254
257
it ( 'issue 1414 - should not continue running timers after scope is destroyed' , function ( ) {
255
258
testSlideActive ( 0 ) ;
256
- $timeout . flush ( ) ;
259
+ $interval . flush ( scope . interval ) ;
257
260
testSlideActive ( 1 ) ;
258
- $timeout . flush ( ) ;
261
+ $interval . flush ( scope . interval ) ;
259
262
testSlideActive ( 2 ) ;
260
- $timeout . flush ( ) ;
263
+ $interval . flush ( scope . interval ) ;
261
264
testSlideActive ( 0 ) ;
265
+ spyOn ( $interval , 'cancel' ) . andCallThrough ( ) ;
262
266
scope . $destroy ( ) ;
263
- expect ( $timeout . flush ) . toThrow ( 'No deferred tasks to be flushed' ) ;
267
+ expect ( $interval . cancel ) . toHaveBeenCalled ( ) ;
264
268
} ) ;
265
269
266
270
} ) ;
@@ -326,12 +330,12 @@ describe('carousel', function() {
326
330
scope . interval = 2000 ;
327
331
scope . $digest ( ) ;
328
332
329
- $timeout . flush ( ) ;
333
+ $interval . flush ( scope . interval ) ;
330
334
expect ( scope . next . calls . length ) . toBe ( 1 ) ;
331
335
332
336
scope . $destroy ( ) ;
333
337
334
- $timeout . flush ( scope . interval ) ;
338
+ $interval . flush ( scope . interval ) ;
335
339
expect ( scope . next . calls . length ) . toBe ( 1 ) ;
336
340
} ) ;
337
341
} ) ;
0 commit comments