Skip to content

Commit

Permalink
Failing test – clear the right timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceharris committed Dec 6, 2017
1 parent da278c6 commit e8e4dca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/LoadingIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class LoadingIndicator extends Component {
}

componentWillUnmount() {
clearTimeout(this._delayTimer);
clearTimeout();
}

render() {
Expand Down
5 changes: 5 additions & 0 deletions src/components/LoadingIndicator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ describe('LoadingIndicator', () => {
describe('on unmount', () => {
it('should clear timeout', () => {
jest.useFakeTimers();

const mockTimerValue = 12345;
setTimeout.mockReturnValue(mockTimerValue);

const wrapper = mount(
<LoadingIndicator isLoading={true}>
<div>ahoy!</div>
Expand All @@ -59,6 +63,7 @@ describe('LoadingIndicator', () => {

wrapper.unmount();
expect(clearTimeout.mock.calls.length).toEqual(1);
expect(clearTimeout.mock.calls[0][0]).toEqual(mockTimerValue);
});
});
});

0 comments on commit e8e4dca

Please sign in to comment.