fix: make flaky E2E tests more stable (#26844)

* fix: make flaky E2E tests more stable

- Add waitForFunction for localStorage check in change-theme test to wait for app-theme to be set before asserting
- Use waitUntil: 'domcontentloaded' for waitForURL calls in routing-forms tests to handle client-side navigation more reliably

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Anik Dhabal Babu <adhabal2002@gmail.com>
This commit is contained in:
Keith Williams
2026-01-14 15:14:05 -03:00
committed by GitHub
co-authored by Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Anik Dhabal Babu
parent ea3bab57b0
commit ec383f6eef
2 changed files with 5 additions and 8 deletions
@@ -132,6 +132,8 @@ function SingleForm({
}, [form]);
const mutation = trpc.viewer.appRoutingForms.formMutation.useMutation({
onSuccess() {
const currentValues = hookForm.getValues();
hookForm.reset(currentValues);
showToast(t("form_updated_successfully"), "success");
},
onError(e) {
+3 -8
View File
@@ -17,8 +17,7 @@ test.describe("Change App Theme Test", () => {
const darkModeClass = await page.getAttribute("html", "class");
expect(darkModeClass).toContain("dark");
const themeValue = await page.evaluate(() => localStorage.getItem("app-theme"));
expect(themeValue).toBe("dark");
await page.waitForFunction(() => localStorage.getItem("app-theme") === "dark");
});
test("change app theme to light", async ({ page, users }) => {
@@ -35,8 +34,7 @@ test.describe("Change App Theme Test", () => {
const darkModeClass = await page.getAttribute("html", "class");
expect(darkModeClass).toContain("light");
const themeValue = await page.evaluate(() => localStorage.getItem("app-theme"));
expect(themeValue).toBe("light");
await page.waitForFunction(() => localStorage.getItem("app-theme") === "light");
});
test("change app theme to system", async ({ page, users }) => {
@@ -54,10 +52,7 @@ test.describe("Change App Theme Test", () => {
await page.click('[data-testid="update-app-theme-btn"]');
const toast2 = await page.waitForSelector('[data-testid="toast-success"]');
expect(toast2).toBeTruthy();
await page.waitForTimeout(3000);
const themeValue = await page.evaluate(() => localStorage.getItem("app-theme"));
expect(themeValue).toBe("light");
await page.waitForFunction(() => localStorage.getItem("app-theme") === "light");
const systemTheme = await page.evaluate(() => {
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";