Skip to content

Commit 0f07e89

Browse files
committed
test: add test case exercising this
1 parent 1647035 commit 0f07e89

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/tracing/test/browser/metrics.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,25 @@ describe('MetricsInstrumentation', () => {
183183
trackers.forEach(tracker => expect(tracker).not.toBeCalled());
184184
});
185185

186-
it('initializes trackers when not on node and `global.performance` is available.', () => {
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+
global.process = undefined;
191+
const documentBackup = global.document;
192+
global.document = undefined;
193+
194+
const trackers = ['_trackCLS', '_trackLCP', '_trackFID'].map(tracker =>
195+
jest.spyOn(MetricsInstrumentation.prototype as any, tracker),
196+
);
197+
new MetricsInstrumentation();
198+
global.process = processBackup;
199+
global.document = documentBackup;
200+
201+
trackers.forEach(tracker => expect(tracker).not.toBeCalled());
202+
});
203+
204+
it('initializes trackers when not on node and `global.performance` and `global.document` are available.', () => {
187205
addDOMPropertiesToGlobal(['performance', 'document', 'addEventListener', 'window']);
188206
const backup = global.process;
189207
global.process = undefined;

0 commit comments

Comments
 (0)