File tree Expand file tree Collapse file tree 3 files changed +641
-912
lines changed Expand file tree Collapse file tree 3 files changed +641
-912
lines changed Original file line number Diff line number Diff line change 37
37
"@callstack/eslint-config" : " ^11.0.0" ,
38
38
"@release-it/conventional-changelog" : " ^2.0.0" ,
39
39
"@testing-library/jest-native" : " ~4.0.2" ,
40
- "@types/jest" : " ^27 .0.0" ,
40
+ "@types/jest" : " ^28 .0.0" ,
41
41
"@types/react" : " ^17.0.0" ,
42
42
"@types/react-native" : " ^0.66.6" ,
43
43
"@types/react-test-renderer" : " ^17.0.0" ,
44
- "babel-jest" : " ^27 .0.0" ,
44
+ "babel-jest" : " ^28 .0.0" ,
45
45
"conventional-changelog-cli" : " ^2.0.11" ,
46
46
"cp-cli" : " ^2.0.0" ,
47
47
"dedent" : " ^0.7.0" ,
48
48
"del-cli" : " ^3.0.1" ,
49
49
"eslint" : " ^7.32.0" ,
50
50
"flow-bin" : " ~0.170.0" ,
51
51
"flow-copy-source" : " ^2.0.9" ,
52
- "jest" : " ^27 .0.0" ,
52
+ "jest" : " ^28 .0.0" ,
53
53
"react" : " ^18.0.0" ,
54
54
"react-native" : " ~0.69.1" ,
55
55
"react-test-renderer" : " ^18.0.0" ,
Original file line number Diff line number Diff line change 2
2
/* globals jest */
3
3
const globalObj = typeof window === 'undefined' ? global : window ;
4
4
5
+ type FakeTimersTypes = 'modern' | 'legacy' ;
6
+
5
7
// Currently this fn only supports jest timers, but it could support other test runners in the future.
6
8
function runWithRealTimers < T > ( callback : ( ) => T ) : T {
7
9
const fakeTimersType = getJestFakeTimersType ( ) ;
@@ -12,13 +14,14 @@ function runWithRealTimers<T>(callback: () => T): T {
12
14
const callbackReturnValue = callback ( ) ;
13
15
14
16
if ( fakeTimersType ) {
15
- jest . useFakeTimers ( fakeTimersType ) ;
17
+ const fakeTimersConfig = getFakeTimersConfigFromType ( fakeTimersType ) ;
18
+ jest . useFakeTimers ( fakeTimersConfig ) ;
16
19
}
17
20
18
21
return callbackReturnValue ;
19
22
}
20
23
21
- function getJestFakeTimersType ( ) {
24
+ function getJestFakeTimersType ( ) : FakeTimersTypes | null {
22
25
// istanbul ignore if
23
26
if (
24
27
typeof jest === 'undefined' ||
@@ -49,9 +52,16 @@ function getJestFakeTimersType() {
49
52
// not using Jest's modern fake timers
50
53
}
51
54
}
55
+
52
56
return null ;
53
57
}
54
58
59
+ function getFakeTimersConfigFromType ( type : FakeTimersTypes ) {
60
+ return type === 'legacy'
61
+ ? { legacyFakeTimers : true }
62
+ : { legacyFakeTimers : false } ;
63
+ }
64
+
55
65
const jestFakeTimersAreEnabled = ( ) : boolean =>
56
66
Boolean ( getJestFakeTimersType ( ) ) ;
57
67
You can’t perform that action at this time.
0 commit comments