Skip to content

Commit 814ec26

Browse files
committed
chore: update jest
1 parent bdd8f75 commit 814ec26

File tree

3 files changed

+641
-912
lines changed

3 files changed

+641
-912
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@
3737
"@callstack/eslint-config": "^11.0.0",
3838
"@release-it/conventional-changelog": "^2.0.0",
3939
"@testing-library/jest-native": "~4.0.2",
40-
"@types/jest": "^27.0.0",
40+
"@types/jest": "^28.0.0",
4141
"@types/react": "^17.0.0",
4242
"@types/react-native": "^0.66.6",
4343
"@types/react-test-renderer": "^17.0.0",
44-
"babel-jest": "^27.0.0",
44+
"babel-jest": "^28.0.0",
4545
"conventional-changelog-cli": "^2.0.11",
4646
"cp-cli": "^2.0.0",
4747
"dedent": "^0.7.0",
4848
"del-cli": "^3.0.1",
4949
"eslint": "^7.32.0",
5050
"flow-bin": "~0.170.0",
5151
"flow-copy-source": "^2.0.9",
52-
"jest": "^27.0.0",
52+
"jest": "^28.0.0",
5353
"react": "^18.0.0",
5454
"react-native": "~0.69.1",
5555
"react-test-renderer": "^18.0.0",

src/helpers/timers.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/* globals jest */
33
const globalObj = typeof window === 'undefined' ? global : window;
44

5+
type FakeTimersTypes = 'modern' | 'legacy';
6+
57
// Currently this fn only supports jest timers, but it could support other test runners in the future.
68
function runWithRealTimers<T>(callback: () => T): T {
79
const fakeTimersType = getJestFakeTimersType();
@@ -12,13 +14,14 @@ function runWithRealTimers<T>(callback: () => T): T {
1214
const callbackReturnValue = callback();
1315

1416
if (fakeTimersType) {
15-
jest.useFakeTimers(fakeTimersType);
17+
const fakeTimersConfig = getFakeTimersConfigFromType(fakeTimersType);
18+
jest.useFakeTimers(fakeTimersConfig);
1619
}
1720

1821
return callbackReturnValue;
1922
}
2023

21-
function getJestFakeTimersType() {
24+
function getJestFakeTimersType(): FakeTimersTypes | null {
2225
// istanbul ignore if
2326
if (
2427
typeof jest === 'undefined' ||
@@ -49,9 +52,16 @@ function getJestFakeTimersType() {
4952
// not using Jest's modern fake timers
5053
}
5154
}
55+
5256
return null;
5357
}
5458

59+
function getFakeTimersConfigFromType(type: FakeTimersTypes) {
60+
return type === 'legacy'
61+
? { legacyFakeTimers: true }
62+
: { legacyFakeTimers: false };
63+
}
64+
5565
const jestFakeTimersAreEnabled = (): boolean =>
5666
Boolean(getJestFakeTimersType());
5767

0 commit comments

Comments
 (0)