la-gregory
v1.0.1
Published
jest date mocks
Downloads
18
Readme
la-gregory
A jest date mocking library.
Installation
In package.json
under the jest
, create a setupFiles
array and add jest-date-mock
to the array.
{
"jest": {
"setupFiles": ["jest-date-mock"]
}
}
Usage
import { setDate, advanceDate, clearDateMock, setPerformanceOffset } from 'la-gregory'
it('messes with date', () => { setDate(new Date(1988, 5, 13, 0, 0, 0))
const now = Date.now()
advanceDate(3000) expect(Date.now() - now).toEqual(3000)
advanceDate(-1000) expect(Date.now() - now).toEqual(2000) expect(window.performance.now()).toEqual(2000)
setPerformanceOffset(-500) expect(window.performance.now()).toEqual(1500)
clearDateMock() expect(Date.now().getFullYear()).toBeGreaterThan(1988) })