@@ -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 ( ) {
@@ -152,12 +152,12 @@ describe('carousel', function() {
152
152
//no timeout to flush, interval watch doesn't make a new one when interval is invalid
153
153
testSlideActive ( 0 ) ;
154
154
scope . $apply ( 'interval = 1000' ) ;
155
- $timeout . flush ( ) ;
155
+ $interval . flush ( scope . interval ) ;
156
156
testSlideActive ( 1 ) ;
157
157
scope . $apply ( 'interval = false' ) ;
158
158
testSlideActive ( 1 ) ;
159
159
scope . $apply ( 'interval = 1000' ) ;
160
- $timeout . flush ( ) ;
160
+ $interval . flush ( scope . interval ) ;
161
161
testSlideActive ( 2 ) ;
162
162
} ) ;
163
163
@@ -182,34 +182,35 @@ describe('carousel', function() {
182
182
183
183
it ( 'should be playing by default and cycle through slides' , function ( ) {
184
184
testSlideActive ( 0 ) ;
185
- $timeout . flush ( ) ;
185
+ $interval . flush ( scope . interval ) ;
186
186
testSlideActive ( 1 ) ;
187
- $timeout . flush ( ) ;
187
+ $interval . flush ( scope . interval ) ;
188
188
testSlideActive ( 2 ) ;
189
- $timeout . flush ( ) ;
189
+ $interval . flush ( scope . interval ) ;
190
190
testSlideActive ( 0 ) ;
191
191
} ) ;
192
192
193
193
it ( 'should pause and play on mouseover' , function ( ) {
194
194
testSlideActive ( 0 ) ;
195
- $timeout . flush ( ) ;
195
+ $interval . flush ( scope . interval ) ;
196
196
testSlideActive ( 1 ) ;
197
197
elm . trigger ( 'mouseenter' ) ;
198
- expect ( $timeout . flush ) . toThrow ( ) ; //pause should cancel current timeout
198
+ testSlideActive ( 1 ) ;
199
+ $interval . flush ( scope . interval ) ;
199
200
testSlideActive ( 1 ) ;
200
201
elm . trigger ( 'mouseleave' ) ;
201
- $timeout . flush ( ) ;
202
+ $interval . flush ( scope . interval ) ;
202
203
testSlideActive ( 2 ) ;
203
204
} ) ;
204
205
205
206
it ( 'should not pause on mouseover if noPause' , function ( ) {
206
207
scope . $apply ( 'nopause = true' ) ;
207
208
testSlideActive ( 0 ) ;
208
209
elm . trigger ( 'mouseenter' ) ;
209
- $timeout . flush ( ) ;
210
+ $interval . flush ( scope . interval ) ;
210
211
testSlideActive ( 1 ) ;
211
212
elm . trigger ( 'mouseleave' ) ;
212
- $timeout . flush ( ) ;
213
+ $interval . flush ( scope . interval ) ;
213
214
testSlideActive ( 2 ) ;
214
215
} ) ;
215
216
@@ -219,7 +220,7 @@ describe('carousel', function() {
219
220
scope . $apply ( 'slides.splice(0,1)' ) ;
220
221
expect ( elm . find ( 'div.item' ) . length ) . toBe ( 2 ) ;
221
222
testSlideActive ( 1 ) ;
222
- $timeout . flush ( ) ;
223
+ $interval . flush ( scope . interval ) ;
223
224
testSlideActive ( 0 ) ;
224
225
scope . $apply ( 'slides.splice(1,1)' ) ;
225
226
expect ( elm . find ( 'div.item' ) . length ) . toBe ( 1 ) ;
@@ -253,14 +254,15 @@ describe('carousel', function() {
253
254
254
255
it ( 'issue 1414 - should not continue running timers after scope is destroyed' , function ( ) {
255
256
testSlideActive ( 0 ) ;
256
- $timeout . flush ( ) ;
257
+ $interval . flush ( scope . interval ) ;
257
258
testSlideActive ( 1 ) ;
258
- $timeout . flush ( ) ;
259
+ $interval . flush ( scope . interval ) ;
259
260
testSlideActive ( 2 ) ;
260
- $timeout . flush ( ) ;
261
+ $interval . flush ( scope . interval ) ;
261
262
testSlideActive ( 0 ) ;
263
+ spyOn ( $interval , 'cancel' ) ;
262
264
scope . $destroy ( ) ;
263
- expect ( $timeout . flush ) . toThrow ( 'No deferred tasks to be flushed' ) ;
265
+ expect ( $interval . cancel ) . toHaveBeenCalled ( ) ;
264
266
} ) ;
265
267
266
268
} ) ;
@@ -326,12 +328,12 @@ describe('carousel', function() {
326
328
scope . interval = 2000 ;
327
329
scope . $digest ( ) ;
328
330
329
- $timeout . flush ( ) ;
331
+ $interval . flush ( scope . interval ) ;
330
332
expect ( scope . next . calls . length ) . toBe ( 1 ) ;
331
333
332
334
scope . $destroy ( ) ;
333
335
334
- $timeout . flush ( scope . interval ) ;
336
+ $interval . flush ( scope . interval ) ;
335
337
expect ( scope . next . calls . length ) . toBe ( 1 ) ;
336
338
} ) ;
337
339
} ) ;
0 commit comments