Skip to content

Commit 65522c6

Browse files
Add test for clearInterval
1 parent 6dc815e commit 65522c6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/components/manager.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const _mockContext = function(slide, routeParams) {
1414
controls: {},
1515
progress: {
1616
pacman: []
17+
},
18+
autoplay: {
19+
pause: {}
1720
}
1821
},
1922
store: {
@@ -199,4 +202,22 @@ describe('<Manager />', () => {
199202
// slide 4 (index 3) the delta should be 3 - 1, thus 2.
200203
expect(managerInstance._getOffset(1)).toEqual(2);
201204
});
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+
});
202223
});

0 commit comments

Comments
 (0)