@@ -35,6 +35,7 @@ describe('startIdleNavigationSpan', () => {
3535 jest . useFakeTimers ( ) ;
3636 NATIVE . enableNative = true ;
3737 mockedAppState . isAvailable = true ;
38+ mockedAppState . currentState = 'active' ;
3839 mockedAppState . addEventListener = ( _ , listener ) => {
3940 mockedAppState . listener = listener ;
4041 return {
@@ -82,6 +83,37 @@ describe('startIdleNavigationSpan', () => {
8283 expect ( spanToJSON ( transaction ! ) . timestamp ) . toBeDefined ( ) ;
8384 } ) ;
8485
86+ it ( 'Returns non-recording span when app is already in background' , ( ) => {
87+ mockedAppState . currentState = 'background' ;
88+
89+ const span = startIdleNavigationSpan ( {
90+ name : 'test' ,
91+ } ) ;
92+
93+ // Non-recording spans don't become active
94+ expect ( getActiveSpan ( ) ) . toBeUndefined ( ) ;
95+
96+ // Verify it's a non-recording span
97+ expect ( span ) . toBeDefined ( ) ;
98+ expect ( span . constructor . name ) . toBe ( 'SentryNonRecordingSpan' ) ;
99+
100+ // No AppState listener should be set up for non-recording spans
101+ expect ( mockedAppState . removeSubscription ) . not . toHaveBeenCalled ( ) ;
102+ } ) ;
103+
104+ it ( 'Does not set up AppState listener for background spans' , ( ) => {
105+ mockedAppState . currentState = 'background' ;
106+
107+ startIdleNavigationSpan ( {
108+ name : 'test' ,
109+ } ) ;
110+
111+ mockedAppState . setState ( 'active' ) ;
112+
113+ // No subscription removal should happen since no listener was set up
114+ expect ( mockedAppState . removeSubscription ) . not . toHaveBeenCalled ( ) ;
115+ } ) ;
116+
85117 describe ( 'Start a new active root span (without parent)' , ( ) => {
86118 it ( 'Starts a new span when there is no active span' , ( ) => {
87119 const span = startIdleNavigationSpan ( {
0 commit comments