Skip to content

Commit aeb1ab5

Browse files
authored
feat: Flush animation frames every 16ms when using legacy timers (#11567)
1 parent d1882f2 commit aeb1ab5

File tree

7 files changed

+386
-21
lines changed

7 files changed

+386
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Features
44

5+
- `[jest-fake-timers]` Flush callbacks scheduled with `requestAnimationFrame` every 16ms when using legacy timers. ([#11523](https://github.com/facebook/jest/pull/11567))
6+
57
### Fixes
68

79
- `[jest-reporter]` Allow `node-notifier@10` as peer dependency ([#11523](https://github.com/facebook/jest/pull/11523))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
/* global requestAnimationFrame */
9+
10+
'use strict';
11+
12+
test('requestAnimationFrame', () => {
13+
jest.useFakeTimers('legacy');
14+
let frameTimestamp = -1;
15+
requestAnimationFrame(timestamp => {
16+
frameTimestamp = timestamp;
17+
});
18+
19+
jest.advanceTimersByTime(15);
20+
21+
expect(frameTimestamp).toBe(-1);
22+
23+
jest.advanceTimersByTime(1);
24+
25+
expect(frameTimestamp).toBeGreaterThan(15);
26+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "jsdom"
4+
}
5+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
/* global requestAnimationFrame */
9+
10+
'use strict';
11+
12+
test('requestAnimationFrame', () => {
13+
jest.useFakeTimers('modern');
14+
let frameTimestamp = -1;
15+
requestAnimationFrame(timestamp => {
16+
frameTimestamp = timestamp;
17+
});
18+
19+
jest.advanceTimersByTime(15);
20+
21+
expect(frameTimestamp).toBe(-1);
22+
23+
jest.advanceTimersByTime(1);
24+
25+
expect(frameTimestamp).toBeGreaterThan(15);
26+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "jsdom"
4+
}
5+
}

0 commit comments

Comments
 (0)