@@ -14,7 +14,6 @@ describe('metrics.timing', () => {
14
14
} ) ;
15
15
16
16
beforeEach ( ( ) => {
17
- jest . useFakeTimers ( 'legacy' ) ;
18
17
testClient = new TestClient ( options ) ;
19
18
setCurrentClient ( testClient ) ;
20
19
} ) ;
@@ -78,7 +77,10 @@ describe('metrics.timing', () => {
78
77
} ) ;
79
78
80
79
it ( 'works with a sync callback' , async ( ) => {
81
- const res = metricsDefault . timing ( 't1' , ( ) => 'oho' ) ;
80
+ const res = metricsDefault . timing ( 't1' , ( ) => {
81
+ sleepSync ( 200 ) ;
82
+ return 'oho' ;
83
+ } ) ;
82
84
expect ( res ) . toStrictEqual ( 'oho' ) ;
83
85
84
86
const sendSpy = jest . spyOn ( testClient . getTransport ( ) ! , 'send' ) ;
@@ -93,7 +95,10 @@ describe('metrics.timing', () => {
93
95
} ) ;
94
96
95
97
it ( 'works with an async callback' , async ( ) => {
96
- const res = metricsDefault . timing ( 't1' , async ( ) => 'oho' ) ;
98
+ const res = metricsDefault . timing ( 't1' , async ( ) => {
99
+ await new Promise ( resolve => setTimeout ( resolve , 200 ) ) ;
100
+ return 'oho' ;
101
+ } ) ;
97
102
expect ( res ) . toBeInstanceOf ( Promise ) ;
98
103
expect ( await res ) . toStrictEqual ( 'oho' ) ;
99
104
@@ -108,3 +113,12 @@ describe('metrics.timing', () => {
108
113
] ) ;
109
114
} ) ;
110
115
} ) ;
116
+
117
+ function sleepSync ( milliseconds : number ) : void {
118
+ const start = Date . now ( ) ;
119
+ for ( let i = 0 ; i < 1e7 ; i ++ ) {
120
+ if ( new Date ( ) . getTime ( ) - start > milliseconds ) {
121
+ break ;
122
+ }
123
+ }
124
+ }
0 commit comments