-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure JS.show/hide/toggle work as before, fix focus (#3692)
* ensure JS.show/hide/toggle work as before, fix focus Fixes #3691. Fixes #3675. Fixes #3563. Relates to: #3657 Relates to: f06877a * try to clarify comments
- Loading branch information
Showing
4 changed files
with
119 additions
and
26 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// https://github.com/jestjs/jest/pull/14598#issuecomment-1748047560 | ||
// TODO: remove this once jest.advanceTimersToNextFrame() is available | ||
// ensure you are using "modern" fake timers | ||
// 1. before doing anything, grab the start time `setStartSystemTime()` | ||
// 2. step through frames by using `advanceTimersToNextFrame()` | ||
|
||
let startTime = null | ||
|
||
/** Record the initial (mocked) system start time | ||
* | ||
* This is no longer needed once `jest.advanceTimersToNextFrame()` is available | ||
* https://github.com/jestjs/jest/pull/14598 | ||
*/ | ||
global.setStartSystemTime = () => { | ||
startTime = Date.now() | ||
} | ||
|
||
/** Step forward a single animation frame | ||
* | ||
* This is no longer needed once `jest.advanceTimersToNextFrame()` is available | ||
* https://github.com/jestjs/jest/pull/14598 | ||
*/ | ||
global.advanceTimersToNextFrame = () => { | ||
if(startTime == null){ | ||
throw new Error("Must call `setStartSystemTime` before using `advanceTimersToNextFrame()`") | ||
} | ||
|
||
// Stealing logic from sinon fake timers | ||
// https://github.com/sinonjs/fake-timers/blob/fc312b9ce96a4ea2c7e60bb0cccd2c604b75cdbd/src/fake-timers-src.js#L1102-L1105 | ||
const timePassedInFrame = (Date.now() - startTime) % 16 | ||
const timeToNextFrame = 16 - timePassedInFrame | ||
jest.advanceTimersByTime(timeToNextFrame) | ||
} |