Skip to content

Commit 6809ae9

Browse files
committed
testing: should handle invalid token on page reload gracefully
1 parent aa963af commit 6809ae9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

e2e/auth.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)