@@ -64,13 +64,21 @@ describe("createMatrixRoomMessageHandler inbound body formatting", () => {
6464 function latestFinalizedReplyContext (
6565 finalizeInboundContext : MatrixHandlerHarness [ "finalizeInboundContext" ] ,
6666 ) {
67- return vi . mocked ( finalizeInboundContext ) . mock . calls . at ( - 1 ) ?. [ 0 ] as FinalizedReplyContext ;
67+ const calls = vi . mocked ( finalizeInboundContext ) . mock . calls ;
68+ const call = calls [ calls . length - 1 ] ;
69+ if ( ! call ) {
70+ throw new Error ( "expected finalizeInboundContext call" ) ;
71+ }
72+ return call [ 0 ] as FinalizedReplyContext ;
6873 }
6974
7075 function latestSessionKey ( recordInboundSession : MatrixHandlerHarness [ "recordInboundSession" ] ) {
71- const context = vi . mocked ( recordInboundSession ) . mock . calls . at ( - 1 ) ?. [ 0 ] as
72- | { sessionKey ?: string }
73- | undefined ;
76+ const calls = vi . mocked ( recordInboundSession ) . mock . calls ;
77+ const call = calls [ calls . length - 1 ] ;
78+ if ( ! call ) {
79+ throw new Error ( "expected recordInboundSession call" ) ;
80+ }
81+ const context = call [ 0 ] as { sessionKey ?: string } ;
7482 return context ?. sessionKey ;
7583 }
7684
@@ -355,11 +363,7 @@ describe("createMatrixRoomMessageHandler inbound body formatting", () => {
355363 } ) ,
356364 ) ;
357365
358- const finalized = vi . mocked ( finalizeInboundContext ) . mock . calls . at ( - 1 ) ?. [ 0 ] as {
359- ReplyToBody ?: string ;
360- ReplyToSender ?: string ;
361- ThreadStarterBody ?: string ;
362- } ;
366+ const finalized = latestFinalizedReplyContext ( finalizeInboundContext ) ;
363367 expect ( finalized . ThreadStarterBody ) . toBeUndefined ( ) ;
364368 expect ( finalized . ReplyToBody ) . toBeUndefined ( ) ;
365369 expect ( finalized . ReplyToSender ) . toBeUndefined ( ) ;
0 commit comments