File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -81,4 +81,20 @@ test.describe('Authentication', () => {
8181 // Should still be logged in
8282 await expect ( page . locator ( `a[href="/profile/${ user . username } "]` ) ) . toBeVisible ( ) ;
8383 } ) ;
84+
85+ test ( 'should handle invalid token on page reload gracefully' , async ( { page } ) => {
86+ // Set an invalid token in localStorage before navigating
87+ await page . goto ( '/' ) ;
88+ await page . evaluate ( ( ) => {
89+ localStorage . setItem ( 'jwtToken' , 'invalid-token-that-will-cause-401' ) ;
90+ } ) ;
91+ // Reload the page - this should NOT cause a blank screen
92+ await page . reload ( ) ;
93+ // The app should still load and show the unauthenticated UI
94+ await expect ( page . locator ( 'a[href="/login"]' ) ) . toBeVisible ( ) ;
95+ await expect ( page . locator ( 'a[href="/register"]' ) ) . toBeVisible ( ) ;
96+ // The invalid token should be cleared
97+ const token = await page . evaluate ( ( ) => localStorage . getItem ( 'jwtToken' ) ) ;
98+ expect ( token ) . toBeNull ( ) ;
99+ } ) ;
84100} ) ;
You can’t perform that action at this time.
0 commit comments