diff --git a/e2e/theme.spec.js b/e2e/theme.spec.js index 1c0715a45..9fbb10f68 100644 --- a/e2e/theme.spec.js +++ b/e2e/theme.spec.js @@ -107,6 +107,15 @@ test("public profile page theme selector works without authentication", async ({ // Clear cookies so visitor is unauthenticated await page.context().clearCookies(); + // OVERRIDE: Mock the session endpoint to return an unauthenticated state + // This prevents the authenticated mock from beforeEach from leaking into this test. + await page.route("**/api/auth/session**", async (route) => { + await route.fulfill({ + contentType: "application/json", + body: JSON.stringify({}), // NextAuth interprets an empty object (or null) as unauthenticated + }); + }); + // Navigate to any public profile URL — will show "Profile Not Found" // but the full layout (including ThemeToggle) still renders await page.goto("/u/no-such-user-for-e2e-test", { waitUntil: "load" });