Created
March 2, 2018 16:42
-
-
Save bruceharris/74d7930c55da701b55bb94a69d5b0d9e to your computer and use it in GitHub Desktop.
React Unit Testing Example 17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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