diff --git a/CHANGELOG.md b/CHANGELOG.md index 7793451b3ace..6c50552d21ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - `[babel-preset-jest]` [**BREAKING**] Export a function instead of an object for Babel 7 compatibility ([#7203](https://github.com/facebook/jest/pull/7203)) - `[expect]` Check constructor equality in .toStrictEqual() ([#7005](https://github.com/facebook/jest/pull/7005)) - `[jest-util]` Add `jest.getTimerCount()` to get the count of scheduled fake timers ([#7285](https://github.com/facebook/jest/pull/7285)) +- `[jest-util]`[**BREAKING**] Replace Jest's fake timers implementation with Lolex ([#5171](https://github.com/facebook/jest/pull/5171)) ### Fixes diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index edb1ff542587..7bfdc634ae5b 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -447,6 +447,14 @@ This means, if any timers have been scheduled (but have not yet executed), they Returns the number of fake timers still left to run. +### `.jest.setSystemTime()` + +Set the current system time used by fake timers. Simulates a user changing the system clock while your program is running. It affects the current time but it does not in itself cause e.g. timers to fire; they will fire exactly as they would have done without the call to `jest.setSystemTime()`. + +### `.jest.getRealSystemTime()` + +When mocking time, `Date.now()` will also be mocked. If you for some reason need access to the real current time, you can invoke this function. + ## Misc ### `jest.setTimeout(timeout)` diff --git a/packages/jest-util/src/__tests__/fakeTimers.test.js b/packages/jest-util/src/__tests__/fakeTimers.test.js index 5c6f4ee56e97..89a9323e8f22 100644 --- a/packages/jest-util/src/__tests__/fakeTimers.test.js +++ b/packages/jest-util/src/__tests__/fakeTimers.test.js @@ -491,7 +491,7 @@ describe('FakeTimers', () => { }); timers.runOnlyPendingTimers(); - expect(runOrder).toEqual([ + const firsRunOrder = [ 'mock4', 'mock5', 'mock2', @@ -502,20 +502,13 @@ describe('FakeTimers', () => { 'mock3', 'mock1', 'mock2', - ]); + ]; + + expect(runOrder).toEqual(firsRunOrder); timers.runOnlyPendingTimers(); expect(runOrder).toEqual([ - 'mock4', - 'mock5', - 'mock2', - 'mock2', - 'mock1', - 'mock2', - 'mock2', - 'mock3', - 'mock1', - 'mock2', + ...firsRunOrder, 'mock2', 'mock1', 'mock2',