Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bruceharris
Created March 2, 2018 16:27
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/86238a77f9c74db32c12f40e712423be to your computer and use it in GitHub Desktop.
Save bruceharris/86238a77f9c74db32c12f40e712423be to your computer and use it in GitHub Desktop.
React Unit Testing Example 13
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