File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1+ import { wait } from '.' ;
2+
3+ it ( 'returns a promise that resolves after the specified amount of time' , async ( ) => {
4+ jest . useFakeTimers ( ) ;
5+
6+ let value : number = 1 ;
7+
8+ wait ( 1000 ) . then ( ( ) => {
9+ value ++ ;
10+ } ) ;
11+
12+ expect ( value ) . toBe ( 1 ) ;
13+
14+ jest . advanceTimersByTime ( 500 ) ;
15+
16+ await Promise . resolve ( ) ;
17+
18+ expect ( value ) . toBe ( 1 ) ;
19+
20+ jest . advanceTimersByTime ( 500 ) ;
21+
22+ await Promise . resolve ( ) ;
23+
24+ expect ( value ) . toBe ( 2 ) ;
25+
26+ jest . useRealTimers ( ) ;
27+ } ) ;
Original file line number Diff line number Diff line change 22 * Returns a promise that resolves after the specified amount of time in milliseconds.
33 * @param ms Amount in milliseconds to wait.
44 */
5- export const wait = ( ms : number ) => new Promise ( ( res ) => setTimeout ( res , ms ) )
5+ export const wait = ( ms : number ) => new Promise ( res => setTimeout ( res , ms ) ) ;
You can’t perform that action at this time.
0 commit comments