@@ -213,6 +213,9 @@ describe('LocalStream', () => {
213213
214214 const inputTrack = audioStream . getTracks ( ) [ 0 ] ;
215215 jest . spyOn ( inputTrack , 'getSettings' ) . mockReturnValue ( audioSettings ) ;
216+ jest . spyOn ( inputTrack , 'stop' ) . mockImplementation ( ( ) => {
217+ ( inputTrack as { readyState : string } ) . readyState = 'ended' ;
218+ } ) ;
216219
217220 const eventHandlers = new Map < string , ( ...args : unknown [ ] ) => void > ( ) ;
218221 effect = {
@@ -397,6 +400,10 @@ describe('LocalStream', () => {
397400 expect . hasAssertions ( ) ;
398401
399402 const endedSpy = jest . spyOn ( audioLocalStream [ StreamEventNames . Ended ] , 'emit' ) ;
403+ const outputTrackChangeSpy = jest . spyOn (
404+ audioLocalStream [ LocalStreamEventNames . OutputTrackChange ] ,
405+ 'emit'
406+ ) ;
400407
401408 getUserMediaSpy
402409 . mockRejectedValueOnce ( new Error ( 'OverconstrainedError' ) )
@@ -406,6 +413,28 @@ describe('LocalStream', () => {
406413
407414 expect ( getUserMediaSpy ) . toHaveBeenCalledTimes ( 2 ) ;
408415 expect ( endedSpy ) . toHaveBeenCalledWith ( ) ;
416+ expect ( outputTrackChangeSpy ) . not . toHaveBeenCalled ( ) ;
417+ } ) ;
418+
419+ it ( 'should fall back to raw mic track when replaceInputTrack fails' , async ( ) => {
420+ expect . hasAssertions ( ) ;
421+
422+ const endedSpy = jest . spyOn ( audioLocalStream [ StreamEventNames . Ended ] , 'emit' ) ;
423+
424+ ( effect . replaceInputTrack as jest . Mock ) . mockRejectedValueOnce (
425+ new Error ( 'AudioContext closed' )
426+ ) ;
427+
428+ ( newAudioTrack as { readyState : string } ) . readyState = 'live' ;
429+
430+ ( audioStream . addTrack as jest . Mock ) . mockImplementation ( ( track : MediaStreamTrack ) => {
431+ ( audioStream . getTracks as jest . Mock ) . mockReturnValue ( [ track ] ) ;
432+ } ) ;
433+
434+ await constraintsHandler ( { autoGainControl : false } ) ;
435+
436+ expect ( endedSpy ) . not . toHaveBeenCalled ( ) ;
437+ expect ( effect . replaceInputTrack ) . toHaveBeenCalledWith ( newAudioTrack ) ;
409438 } ) ;
410439
411440 it ( 'should preserve the enabled state of the track after re-acquisition' , async ( ) => {
0 commit comments