File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -213,6 +213,9 @@ export class Manager extends Component {
213
213
214
214
componentWillUnmount ( ) {
215
215
this . _detachEvents ( ) ;
216
+ if ( this . autoplayInterval ) {
217
+ clearInterval ( this . autoplayInterval ) ;
218
+ }
216
219
}
217
220
218
221
_attachEvents ( ) {
Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ const _mockContext = function(slide, routeParams) {
14
14
controls : { } ,
15
15
progress : {
16
16
pacman : [ ]
17
+ } ,
18
+ autoplay : {
19
+ pause : { }
17
20
}
18
21
} ,
19
22
store : {
@@ -199,4 +202,22 @@ describe('<Manager />', () => {
199
202
// slide 4 (index 3) the delta should be 3 - 1, thus 2.
200
203
expect ( managerInstance . _getOffset ( 1 ) ) . toEqual ( 2 ) ;
201
204
} ) ;
205
+
206
+ test ( 'should cancel autoplay when component unmounts' , ( ) => {
207
+ const setIntervalSpy = jest . spyOn ( window , 'setInterval' ) ;
208
+ const clearIntervalSpy = jest . spyOn ( window , 'clearInterval' ) ;
209
+ const wrapper = mount (
210
+ < Manager autoplay autoplayOnStart >
211
+ < MockSlide />
212
+ < MockSlide />
213
+ < MockSlide />
214
+ </ Manager > ,
215
+ { context : _mockContext ( 1 , [ ] ) , childContextTypes : _mockChildContext ( ) }
216
+ ) ;
217
+ expect ( setIntervalSpy . mock . calls . length ) . toBe ( 1 ) ;
218
+ wrapper . unmount ( ) ;
219
+ // Called once in `Manager._startAutoplay`
220
+ // and again in `Manager.componentWillUnmount`
221
+ expect ( clearIntervalSpy . mock . calls . length ) . toBe ( 2 ) ;
222
+ } ) ;
202
223
} ) ;
You can’t perform that action at this time.
0 commit comments