@@ -323,5 +323,61 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes], withPattern:
323323 const userId = await userIdElement . textContent ( ) ;
324324 expect ( userId ) . toMatch ( / ^ u s e r _ / ) ;
325325 } ) ;
326+
327+ test ( 'sign out completes and navigation promise resolves' , async ( { page, context } ) => {
328+ const u = createTestUtils ( { app, page, context } ) ;
329+
330+ // Sign in
331+ await u . po . signIn . goTo ( ) ;
332+ await u . po . signIn . signInWithEmailAndInstantPassword ( {
333+ email : fakeUser . email ,
334+ password : fakeUser . password ,
335+ } ) ;
336+ await u . po . expect . toBeSignedIn ( ) ;
337+
338+ // Navigate to a non-root page to ensure post-sign-out navigation is a real route change
339+ await u . page . goToRelative ( '/auth-server-component' ) ;
340+ await expect ( u . page . getByText ( 'auth() in Server Component' ) ) . toBeVisible ( ) ;
341+
342+ // Sign out by explicitly awaiting the full signOut() promise.
343+ // Internally, signOut() calls: onBeforeSetActive (cache invalidation) →
344+ // session removal → navigate(redirectUrl) via routerPush → useInternalNavFun →
345+ // startTransition(() => router.push(to)).
346+ // The navigate() call awaits the promise from useInternalNavFun.
347+ // If isPending doesn't cycle (the concern from removing usePathname in #7989),
348+ // the navigation promise hangs and this evaluate call times out.
349+ await page . evaluate ( async ( ) => {
350+ await window . Clerk . signOut ( ) ;
351+ } ) ;
352+
353+ await u . po . expect . toBeSignedOut ( ) ;
354+ } ) ;
355+
356+ test ( 'protected route redirects to sign-in after sign out' , async ( { page, context } ) => {
357+ const u = createTestUtils ( { app, page, context } ) ;
358+
359+ // Sign in and access protected route
360+ await u . po . signIn . goTo ( ) ;
361+ await u . po . signIn . signInWithEmailAndInstantPassword ( {
362+ email : fakeUser . email ,
363+ password : fakeUser . password ,
364+ } ) ;
365+ await u . po . expect . toBeSignedIn ( ) ;
366+
367+ await u . page . goToRelative ( '/protected' ) ;
368+ await expect ( u . page . getByText ( 'Protected Route' ) ) . toBeVisible ( ) ;
369+
370+ // Sign out
371+ await page . evaluate ( async ( ) => {
372+ await window . Clerk . signOut ( ) ;
373+ } ) ;
374+
375+ await u . po . expect . toBeSignedOut ( ) ;
376+
377+ // Try to access protected route again — should redirect to sign-in
378+ // This verifies cache invalidation worked correctly alongside navigation
379+ await u . page . goToRelative ( '/protected' ) ;
380+ await expect ( page ) . toHaveURL ( / s i g n - i n / ) ;
381+ } ) ;
326382 } ,
327383) ;
0 commit comments