Skip to content

Instantly share code, notes, and snippets.

@bruceharris
Created March 2, 2018 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruceharris/74d7930c55da701b55bb94a69d5b0d9e to your computer and use it in GitHub Desktop.
Save bruceharris/74d7930c55da701b55bb94a69d5b0d9e to your computer and use it in GitHub Desktop.
React Unit Testing Example 17
describe('on unmount', () => {
it('should clear timeout', () => {
jest.useFakeTimers();
const mockTimerValue = 12345;
setTimeout.mockReturnValue(mockTimerValue);
const wrapper = mount(
<LoadingIndicator isLoading={true}>
<div>ahoy!</div>
</LoadingIndicator>
);
wrapper.unmount();
expect(clearTimeout.mock.calls.length).toEqual(1);
expect(clearTimeout.mock.calls[0][0]).toEqual(mockTimerValue);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment