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