Created
January 6, 2020 17:11
-
-
Save jamesfulford/cb21371ba8d282f396aa38ce737fb086 to your computer and use it in GitHub Desktop.
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
import { renderHook, act } from '@testing-library/react-hooks' | |
import { useFakeTimers, SinonFakeTimers } from 'sinon'; | |
import { useTime } from '.'; | |
describe('useTime (sinon clocks)', () => { | |
let clock: SinonFakeTimers; | |
beforeEach(() => { clock = useFakeTimers(); }); | |
afterEach(() => { clock.restore(); }); | |
it('should update the time based on refresh rate', () => { | |
const { result } = renderHook(() => useTime(100)); | |
const initialTime = result.current; | |
act(() => { | |
clock.tick(99); | |
}); | |
// Don't update yet | |
expect(initialTime).toEqual(result.current); | |
act(() => { | |
clock.tick(1); | |
}); | |
// Updated | |
expect(initialTime).not.toEqual(result.current); | |
expect(result.current.diff(initialTime).milliseconds).toBe(100); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment