11import { afterEach , describe , expect , it , vi } from "vite-plus/test" ;
22
3- const navigation = vi . hoisted ( ( ) => ( { navigate : vi . fn ( ) } ) ) ;
3+ const navigation = vi . hoisted ( ( ) => ( {
4+ navigate : vi . fn ( ) ,
5+ ready : true ,
6+ queue : [ ] as Array < ( ) => void > ,
7+ } ) ) ;
48const optOut = vi . hoisted ( ( ) => ( { optedOut : new Set < string > ( ) } ) ) ;
59
610vi . mock ( "../../lib/rootNavigation" , ( ) => ( {
711 rootNavigationRef : navigation ,
8- whenRootNavigationReady : ( navigate : ( ) => void ) => navigate ( ) ,
12+ whenRootNavigationReady : ( navigate : ( ) => void ) =>
13+ navigation . ready ? navigate ( ) : navigation . queue . push ( navigate ) ,
914} ) ) ;
1015vi . mock ( "./connectOnboardingOptOut" , ( ) => ( {
1116 isConnectOnboardingOptedOut : ( accountId : string ) =>
@@ -18,6 +23,8 @@ afterEach(() => {
1823 clearConnectOnboardingRequest ( ) ;
1924 optOut . optedOut . clear ( ) ;
2025 navigation . navigate . mockReset ( ) ;
26+ navigation . ready = true ;
27+ navigation . queue . length = 0 ;
2128 vi . useRealTimers ( ) ;
2229} ) ;
2330
@@ -54,4 +61,14 @@ describe("requestConnectOnboarding", () => {
5461 await vi . runAllTimersAsync ( ) ;
5562 expect ( navigation . navigate ) . toHaveBeenCalledOnce ( ) ;
5663 } ) ;
64+
65+ it ( "drops a request cleared while it waits for navigation to be ready" , async ( ) => {
66+ vi . useFakeTimers ( ) ;
67+ navigation . ready = false ;
68+ requestConnectOnboarding ( "account-1" ) ;
69+ await vi . runAllTimersAsync ( ) ;
70+ clearConnectOnboardingRequest ( ) ;
71+ for ( const navigate of navigation . queue . splice ( 0 ) ) navigate ( ) ;
72+ expect ( navigation . navigate ) . not . toHaveBeenCalled ( ) ;
73+ } ) ;
5774} ) ;
0 commit comments