@@ -325,15 +325,15 @@ test('stream with huge data chunks', async () => {
325325 const parser = createParser ( { onEvent : mock . onParse } )
326326 await getHugeMessageFixtureStream ( parser . feed )
327327 const hugeMsg = mock . events [ 0 ]
328- if ( hugeMsg . type !== 'event' ) {
328+ if ( ! hugeMsg || hugeMsg . type !== 'event' ) {
329329 throw new Error ( 'First message was not an event' )
330330 }
331331
332332 expect ( hugeMsg . data . length ) . toBe ( 4808512 )
333333
334334 const receivedHash = createHash ( 'sha256' ) . update ( hugeMsg . data ) . digest ( 'hex' )
335335 const hashMsg = mock . events [ 1 ]
336- if ( hashMsg . type !== 'event' ) {
336+ if ( ! hashMsg || hashMsg . type !== 'event' ) {
337337 throw new Error ( 'Second message was not an event' )
338338 }
339339
@@ -387,7 +387,7 @@ test('calls onError when the stream is invalid but not newline-terminated (throu
387387 expect ( onEvent ) . not . toHaveBeenCalled ( )
388388 expect ( onError ) . toHaveBeenCalled ( )
389389
390- const error = onError . mock . calls [ 0 ] [ 0 ]
390+ const error = onError . mock . calls [ 0 ] ?. [ 0 ]
391391 expect ( error ) . toBeInstanceOf ( ParseError )
392392 expect ( error ) . toMatchObject ( {
393393 type : 'unknown-field' ,
@@ -411,7 +411,7 @@ test('calls onError when the stream is invalid (through newline)', async () => {
411411 expect ( onEvent ) . not . toHaveBeenCalled ( )
412412 expect ( onError ) . toHaveBeenCalled ( )
413413
414- const error = onError . mock . calls [ 0 ] [ 0 ]
414+ const error = onError . mock . calls [ 0 ] ?. [ 0 ]
415415 expect ( error ) . toBeInstanceOf ( ParseError )
416416 expect ( error ) . toMatchObject ( {
417417 type : 'unknown-field' ,
@@ -430,7 +430,7 @@ test('calls onError when the stream is invalid (no field separator)', async () =
430430 expect ( onEvent ) . not . toHaveBeenCalled ( )
431431 expect ( onError ) . toHaveBeenCalled ( )
432432
433- const error = onError . mock . calls [ 0 ] [ 0 ]
433+ const error = onError . mock . calls [ 0 ] ?. [ 0 ]
434434 expect ( error ) . toBeInstanceOf ( ParseError )
435435 expect ( error ) . toMatchObject ( {
436436 type : 'unknown-field' ,
0 commit comments