1
1
import * as React from 'react' ;
2
2
import { Text , TouchableOpacity , View } from 'react-native' ;
3
3
import { fireEvent , render , waitFor } from '..' ;
4
- import { TimerMode } from './timerUtils' ;
5
4
6
5
class Banana extends React . Component < any > {
7
6
changeFresh = ( ) => {
@@ -79,36 +78,26 @@ test('waits for element with custom interval', async () => {
79
78
expect ( mockFn ) . toHaveBeenCalledTimes ( 2 ) ;
80
79
} ) ;
81
80
82
- test ( 'waits for element until it stops throwing using modern fake timers' , async ( ) => {
83
- jest . useFakeTimers ( 'modern' ) ;
84
- const { getByText, queryByText } = render ( < BananaContainer /> ) ;
85
-
86
- fireEvent . press ( getByText ( 'Change freshness!' ) ) ;
87
- expect ( queryByText ( 'Fresh' ) ) . toBeNull ( ) ;
88
-
89
- jest . advanceTimersByTime ( 300 ) ;
90
- const freshBananaText = await waitFor ( ( ) => getByText ( 'Fresh' ) ) ;
91
-
92
- expect ( freshBananaText . props . children ) . toBe ( 'Fresh' ) ;
93
- } ) ;
81
+ test . each ( [ false , true ] ) (
82
+ 'waits for element until it stops throwing using fake timers (legacyFakeTimers = %s)' ,
83
+ async ( legacyFakeTimers ) => {
84
+ jest . useFakeTimers ( { legacyFakeTimers } ) ;
85
+ const { getByText, queryByText } = render ( < BananaContainer /> ) ;
94
86
95
- test ( 'waits for element until it stops throwing using legacy fake timers' , async ( ) => {
96
- jest . useFakeTimers ( 'legacy' ) ;
97
- const { getByText, queryByText } = render ( < BananaContainer /> ) ;
87
+ fireEvent . press ( getByText ( 'Change freshness!' ) ) ;
88
+ expect ( queryByText ( 'Fresh' ) ) . toBeNull ( ) ;
98
89
99
- fireEvent . press ( getByText ( 'Change freshness!' ) ) ;
100
- expect ( queryByText ( 'Fresh' ) ) . toBeNull ( ) ;
101
-
102
- jest . advanceTimersByTime ( 300 ) ;
103
- const freshBananaText = await waitFor ( ( ) => getByText ( 'Fresh' ) ) ;
90
+ jest . advanceTimersByTime ( 300 ) ;
91
+ const freshBananaText = await waitFor ( ( ) => getByText ( 'Fresh' ) ) ;
104
92
105
- expect ( freshBananaText . props . children ) . toBe ( 'Fresh' ) ;
106
- } ) ;
93
+ expect ( freshBananaText . props . children ) . toBe ( 'Fresh' ) ;
94
+ }
95
+ ) ;
107
96
108
- test . each ( [ TimerMode . Legacy , TimerMode . Modern ] ) (
109
- 'waits for assertion until timeout is met with %s fake timers' ,
110
- async ( fakeTimerType ) => {
111
- jest . useFakeTimers ( fakeTimerType ) ;
97
+ test . each ( [ false , true ] ) (
98
+ 'waits for assertion until timeout is met with fake timers (legacyFakeTimers = %s) ' ,
99
+ async ( legacyFakeTimers ) => {
100
+ jest . useFakeTimers ( { legacyFakeTimers } ) ;
112
101
113
102
const mockFn = jest . fn ( ( ) => {
114
103
throw Error ( 'test' ) ;
@@ -124,10 +113,10 @@ test.each([TimerMode.Legacy, TimerMode.Modern])(
124
113
}
125
114
) ;
126
115
127
- test . each ( [ TimerMode . Legacy , TimerMode . Modern ] ) (
128
- 'waits for assertion until timeout is met with %s fake timers' ,
129
- async ( fakeTimerType ) => {
130
- jest . useFakeTimers ( fakeTimerType ) ;
116
+ test . each ( [ false , true ] ) (
117
+ 'waits for assertion until timeout is met with fake timers (legacyFakeTimers = %s) ' ,
118
+ async ( legacyFakeTimers ) => {
119
+ jest . useFakeTimers ( { legacyFakeTimers } ) ;
131
120
132
121
const mockErrorFn = jest . fn ( ( ) => {
133
122
throw Error ( 'test' ) ;
@@ -150,10 +139,10 @@ test.each([TimerMode.Legacy, TimerMode.Modern])(
150
139
}
151
140
) ;
152
141
153
- test . each ( [ TimerMode . Legacy , TimerMode . Legacy ] ) (
154
- 'awaiting something that succeeds before timeout works with %s fake timers' ,
155
- async ( fakeTimerType ) => {
156
- jest . useFakeTimers ( fakeTimerType ) ;
142
+ test . each ( [ false , true ] ) (
143
+ 'awaiting something that succeeds before timeout works with fake timers (legacyFakeTimers = %s) ' ,
144
+ async ( legacyFakeTimers ) => {
145
+ jest . useFakeTimers ( { legacyFakeTimers } ) ;
157
146
158
147
let calls = 0 ;
159
148
const mockFn = jest . fn ( ( ) => {
0 commit comments