11import * as React from 'react' ;
22import { Text , TouchableOpacity , View } from 'react-native' ;
33import { fireEvent , render , waitFor } from '..' ;
4- import { TimerMode } from './timerUtils' ;
54
65class Banana extends React . Component < any > {
76 changeFresh = ( ) => {
@@ -79,36 +78,26 @@ test('waits for element with custom interval', async () => {
7978 expect ( mockFn ) . toHaveBeenCalledTimes ( 2 ) ;
8079} ) ;
8180
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 /> ) ;
9486
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 ( ) ;
9889
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' ) ) ;
10492
105- expect ( freshBananaText . props . children ) . toBe ( 'Fresh' ) ;
106- } ) ;
93+ expect ( freshBananaText . props . children ) . toBe ( 'Fresh' ) ;
94+ }
95+ ) ;
10796
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 } ) ;
112101
113102 const mockFn = jest . fn ( ( ) => {
114103 throw Error ( 'test' ) ;
@@ -124,10 +113,10 @@ test.each([TimerMode.Legacy, TimerMode.Modern])(
124113 }
125114) ;
126115
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 } ) ;
131120
132121 const mockErrorFn = jest . fn ( ( ) => {
133122 throw Error ( 'test' ) ;
@@ -150,10 +139,10 @@ test.each([TimerMode.Legacy, TimerMode.Modern])(
150139 }
151140) ;
152141
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 } ) ;
157146
158147 let calls = 0 ;
159148 const mockFn = jest . fn ( ( ) => {
0 commit comments