Created
March 2, 2018 16:27
-
-
Save bruceharris/86238a77f9c74db32c12f40e712423be to your computer and use it in GitHub Desktop.
React Unit Testing Example 13
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('when isLoading is true', () => { | |
describe('given 200ms have elapsed', () => { | |
it('should render loading indicator', () => { | |
jest.useFakeTimers(); | |
const wrapper = mount( | |
<LoadingIndicator isLoading={true}> | |
<div>ahoy!</div> | |
</LoadingIndicator> | |
); | |
// assert that setTimeout was called exactly once | |
expect(setTimeout.mock.calls.length).toEqual(1); | |
// assert that the 2nd argument to the call to setTimeout is 200 | |
expect(setTimeout.mock.calls[0][1]).toEqual(200); | |
jest.runAllTimers(); | |
expect(wrapper.html()).toBe('<div>loading...</div>'); | |
wrapper.unmount(); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment