Skip to content

Commit c0d33c0

Browse files
committed
Add test
1 parent 22fd55f commit c0d33c0

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/telemetry/src/api.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ describe('Top level API', () => {
320320
);
321321
});
322322

323-
it('should handle errors when accessing sessionStorage', () => {
323+
it('should handle errors when sessionStorage.getItem throws', () => {
324324
const sessionStorageMock: Partial<Storage> = {
325325
getItem: () => {
326326
throw new Error('SecurityError');
@@ -340,6 +340,26 @@ describe('Top level API', () => {
340340
expect(log.attributes![LOG_ENTRY_ATTRIBUTE_KEYS.SESSION_ID]).to.be
341341
.undefined;
342342
});
343+
344+
it('should handle errors when sessionStorage.setItem throws', () => {
345+
const sessionStorageMock: Partial<Storage> = {
346+
getItem: () => null, // Emulate no existing session ID
347+
setItem: () => {
348+
throw new Error('SecurityError');
349+
}
350+
};
351+
352+
Object.defineProperty(global, 'sessionStorage', {
353+
value: sessionStorageMock,
354+
writable: true
355+
});
356+
357+
captureError(fakeTelemetry, 'error');
358+
359+
expect(emittedLogs.length).to.equal(1);
360+
const log = emittedLogs[0];
361+
expect(log.attributes![LOG_ENTRY_ATTRIBUTE_KEYS.SESSION_ID]).to.be.undefined;
362+
});
343363
});
344364
});
345365

0 commit comments

Comments
 (0)