From 412c0553305e1d71d2edda39409d5527c6d26a2a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 26 Oct 2018 10:00:16 +0200 Subject: [PATCH] update docs --- CHANGELOG.md | 1 + docs/JestObjectAPI.md | 8 ++++++++ .../jest-util/src/__tests__/fake_timers.test.js | 17 +++++------------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c316ca84cad7..5ebdffb85574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,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__/fake_timers.test.js b/packages/jest-util/src/__tests__/fake_timers.test.js index f36eb2ee7aa0..de85e7d83ad7 100644 --- a/packages/jest-util/src/__tests__/fake_timers.test.js +++ b/packages/jest-util/src/__tests__/fake_timers.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',