File tree 1 file changed +26
-2
lines changed
1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ describe('async hook tests', () => {
100
100
101
101
expect ( complete ) . toBe ( true )
102
102
} )
103
- test ( 'should wait for arbitrary expectation to pass when use jest.usedFakeTimers() ' , async ( ) => {
103
+ test ( 'should wait for arbitrary expectation to pass when use jest.usedFakeTimers() and advanceTimersByTime() ' , async ( ) => {
104
104
jest . useFakeTimers ( )
105
105
106
106
const { waitFor } = renderHook ( ( ) => null )
@@ -112,7 +112,31 @@ describe('async hook tests', () => {
112
112
actual = expected
113
113
} , 200 )
114
114
let complete = false
115
- jest . advanceTimersByTime ( 1000 )
115
+ jest . advanceTimersByTime ( 200 )
116
+ await waitFor (
117
+ ( ) => {
118
+ expect ( actual ) . toBe ( expected )
119
+ complete = true
120
+ } ,
121
+ { timeout : 250 , interval : 10 }
122
+ )
123
+
124
+ expect ( complete ) . toBe ( true )
125
+ jest . useRealTimers ( )
126
+ } )
127
+ test ( 'should wait for arbitrary expectation to pass when use jest.usedFakeTimers() and runOnlyPendingTimers() ' , async ( ) => {
128
+ jest . useFakeTimers ( )
129
+
130
+ const { waitFor } = renderHook ( ( ) => null )
131
+
132
+ let actual = 0
133
+ const expected = 1
134
+
135
+ setTimeout ( ( ) => {
136
+ actual = expected
137
+ } , 200 )
138
+ let complete = false
139
+ jest . runOnlyPendingTimers ( )
116
140
await waitFor (
117
141
( ) => {
118
142
expect ( actual ) . toBe ( expected )
You can’t perform that action at this time.
0 commit comments