File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments