@@ -14,12 +14,12 @@ describe('carousel', function() {
1414 } ) ) ;
1515 beforeEach ( module ( 'template/carousel/carousel.html' , 'template/carousel/slide.html' ) ) ;
1616
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_ ) {
1919 $rootScope = _$rootScope_ ;
2020 $compile = _$compile_ ;
2121 $controller = _$controller_ ;
22- $timeout = _$timeout_ ;
22+ $interval = _$interval_ ;
2323 } ) ) ;
2424
2525 describe ( 'basics' , function ( ) {
@@ -148,16 +148,18 @@ describe('carousel', function() {
148148
149149 it ( 'shouldnt go forward if interval is NaN or negative' , function ( ) {
150150 testSlideActive ( 0 ) ;
151+ var previousInterval = scope . interval ;
151152 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 ) ;
153154 testSlideActive ( 0 ) ;
154155 scope . $apply ( 'interval = 1000' ) ;
155- $timeout . flush ( ) ;
156+ $interval . flush ( 1000 ) ;
156157 testSlideActive ( 1 ) ;
157158 scope . $apply ( 'interval = false' ) ;
159+ $interval . flush ( 1000 ) ;
158160 testSlideActive ( 1 ) ;
159161 scope . $apply ( 'interval = 1000' ) ;
160- $timeout . flush ( ) ;
162+ $interval . flush ( 1000 ) ;
161163 testSlideActive ( 2 ) ;
162164 } ) ;
163165
@@ -182,34 +184,35 @@ describe('carousel', function() {
182184
183185 it ( 'should be playing by default and cycle through slides' , function ( ) {
184186 testSlideActive ( 0 ) ;
185- $timeout . flush ( ) ;
187+ $interval . flush ( scope . interval ) ;
186188 testSlideActive ( 1 ) ;
187- $timeout . flush ( ) ;
189+ $interval . flush ( scope . interval ) ;
188190 testSlideActive ( 2 ) ;
189- $timeout . flush ( ) ;
191+ $interval . flush ( scope . interval ) ;
190192 testSlideActive ( 0 ) ;
191193 } ) ;
192194
193195 it ( 'should pause and play on mouseover' , function ( ) {
194196 testSlideActive ( 0 ) ;
195- $timeout . flush ( ) ;
197+ $interval . flush ( scope . interval ) ;
196198 testSlideActive ( 1 ) ;
197199 elm . trigger ( 'mouseenter' ) ;
198- expect ( $timeout . flush ) . toThrow ( ) ; //pause should cancel current timeout
200+ testSlideActive ( 1 ) ;
201+ $interval . flush ( scope . interval ) ;
199202 testSlideActive ( 1 ) ;
200203 elm . trigger ( 'mouseleave' ) ;
201- $timeout . flush ( ) ;
204+ $interval . flush ( scope . interval ) ;
202205 testSlideActive ( 2 ) ;
203206 } ) ;
204207
205208 it ( 'should not pause on mouseover if noPause' , function ( ) {
206209 scope . $apply ( 'nopause = true' ) ;
207210 testSlideActive ( 0 ) ;
208211 elm . trigger ( 'mouseenter' ) ;
209- $timeout . flush ( ) ;
212+ $interval . flush ( scope . interval ) ;
210213 testSlideActive ( 1 ) ;
211214 elm . trigger ( 'mouseleave' ) ;
212- $timeout . flush ( ) ;
215+ $interval . flush ( scope . interval ) ;
213216 testSlideActive ( 2 ) ;
214217 } ) ;
215218
@@ -219,7 +222,7 @@ describe('carousel', function() {
219222 scope . $apply ( 'slides.splice(0,1)' ) ;
220223 expect ( elm . find ( 'div.item' ) . length ) . toBe ( 2 ) ;
221224 testSlideActive ( 1 ) ;
222- $timeout . flush ( ) ;
225+ $interval . flush ( scope . interval ) ;
223226 testSlideActive ( 0 ) ;
224227 scope . $apply ( 'slides.splice(1,1)' ) ;
225228 expect ( elm . find ( 'div.item' ) . length ) . toBe ( 1 ) ;
@@ -253,14 +256,15 @@ describe('carousel', function() {
253256
254257 it ( 'issue 1414 - should not continue running timers after scope is destroyed' , function ( ) {
255258 testSlideActive ( 0 ) ;
256- $timeout . flush ( ) ;
259+ $interval . flush ( scope . interval ) ;
257260 testSlideActive ( 1 ) ;
258- $timeout . flush ( ) ;
261+ $interval . flush ( scope . interval ) ;
259262 testSlideActive ( 2 ) ;
260- $timeout . flush ( ) ;
263+ $interval . flush ( scope . interval ) ;
261264 testSlideActive ( 0 ) ;
265+ spyOn ( $interval , 'cancel' ) . andCallThrough ( ) ;
262266 scope . $destroy ( ) ;
263- expect ( $timeout . flush ) . toThrow ( 'No deferred tasks to be flushed' ) ;
267+ expect ( $interval . cancel ) . toHaveBeenCalled ( ) ;
264268 } ) ;
265269
266270 } ) ;
@@ -326,12 +330,12 @@ describe('carousel', function() {
326330 scope . interval = 2000 ;
327331 scope . $digest ( ) ;
328332
329- $timeout . flush ( ) ;
333+ $interval . flush ( scope . interval ) ;
330334 expect ( scope . next . calls . length ) . toBe ( 1 ) ;
331335
332336 scope . $destroy ( ) ;
333337
334- $timeout . flush ( scope . interval ) ;
338+ $interval . flush ( scope . interval ) ;
335339 expect ( scope . next . calls . length ) . toBe ( 1 ) ;
336340 } ) ;
337341 } ) ;
0 commit comments