@@ -173,6 +173,10 @@ describe('addResourceSpans', () => {
173
173
} ) ;
174
174
175
175
describe ( 'MetricsInstrumentation' , ( ) => {
176
+ afterEach ( ( ) => {
177
+ jest . clearAllMocks ( ) ;
178
+ } ) ;
179
+
176
180
it ( 'does not initialize trackers when on node' , ( ) => {
177
181
const trackers = [ '_trackCLS' , '_trackLCP' , '_trackFID' ] . map ( tracker =>
178
182
jest . spyOn ( MetricsInstrumentation . prototype as any , tracker ) ,
@@ -183,35 +187,38 @@ describe('MetricsInstrumentation', () => {
183
187
trackers . forEach ( tracker => expect ( tracker ) . not . toBeCalled ( ) ) ;
184
188
} ) ;
185
189
186
- it ( 'does not initialize trackers when not on node but `global.document` is not available (in worker) ' , ( ) => {
187
- // window not necessary for this test, but it is here to exercise that it is absence of document that is checked
188
- addDOMPropertiesToGlobal ( [ 'performance' , 'addEventListener' , 'window' ] ) ;
189
- const processBackup = global . process ;
190
+ it ( 'initializes trackers when not on node and `global.performance` and `global.document` are available. ' , ( ) => {
191
+ addDOMPropertiesToGlobal ( [ 'performance' , ' document' , 'addEventListener' , 'window' ] ) ;
192
+
193
+ const backup = global . process ;
190
194
global . process = undefined ;
191
- const documentBackup = global . document ;
192
- global . document = undefined ;
193
195
194
196
const trackers = [ '_trackCLS' , '_trackLCP' , '_trackFID' ] . map ( tracker =>
195
197
jest . spyOn ( MetricsInstrumentation . prototype as any , tracker ) ,
196
198
) ;
199
+
197
200
new MetricsInstrumentation ( ) ;
198
- global . process = processBackup ;
199
- global . document = documentBackup ;
201
+ global . process = backup ;
200
202
201
- trackers . forEach ( tracker => expect ( tracker ) . not . toBeCalled ( ) ) ;
203
+ trackers . forEach ( tracker => expect ( tracker ) . toBeCalled ( ) ) ;
202
204
} ) ;
203
205
204
- it ( 'initializes trackers when not on node and `global.performance` and `global.document` are available.' , ( ) => {
205
- addDOMPropertiesToGlobal ( [ 'performance' , 'document' , 'addEventListener' , 'window' ] ) ;
206
- const backup = global . process ;
206
+ it ( 'does not initialize trackers when not on node but `global.document` is not available (in worker)' , ( ) => {
207
+ // window not necessary for this test, but it is here to exercise that it is absence of document that is checked
208
+ addDOMPropertiesToGlobal ( [ 'performance' , 'addEventListener' , 'window' ] ) ;
209
+
210
+ const processBackup = global . process ;
207
211
global . process = undefined ;
212
+ const documentBackup = global . document ;
213
+ global . document = undefined ;
208
214
209
215
const trackers = [ '_trackCLS' , '_trackLCP' , '_trackFID' ] . map ( tracker =>
210
216
jest . spyOn ( MetricsInstrumentation . prototype as any , tracker ) ,
211
217
) ;
212
218
new MetricsInstrumentation ( ) ;
213
- global . process = backup ;
219
+ global . process = processBackup ;
220
+ global . document = documentBackup ;
214
221
215
- trackers . forEach ( tracker => expect ( tracker ) . toBeCalled ( ) ) ;
222
+ trackers . forEach ( tracker => expect ( tracker ) . not . toBeCalled ( ) ) ;
216
223
} ) ;
217
224
} ) ;
0 commit comments