From ab46e63bf07837ea15c3855f7ee3b5773570238a Mon Sep 17 00:00:00 2001 From: Simon Bernier St-Pierre Date: Sat, 8 Aug 2026 15:04:56 -0400 Subject: [PATCH] try to make e2e test less flaky --- e2e/helpers.ts | 13 ++++++++++++- e2e/tests/meals.spec.ts | 4 +--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/e2e/helpers.ts b/e2e/helpers.ts index be4e328..0ce7cd0 100644 --- a/e2e/helpers.ts +++ b/e2e/helpers.ts @@ -46,12 +46,23 @@ export async function addItem(page: Page, name: string, quantity = "") { } /** Adds an ingredient to the current meal page. */ -export async function addIngredient(page: Page, name: string, quantity = "") { +export async function addIngredient( + page: Page, + name: string, + quantity = "", + category?: string, +) { await page.fill("#ingredient-name", name); + if (category) { + await page.selectOption("#ingredient-category", { label: category }); + } if (quantity) { await page.fill("#ingredient-quantity", quantity); } await page.click("#add-ingredient-button"); + // The form submit is hx-boosted (full body swap to the same URL), so wait for + // the new row to appear. This also acts as a settle point so the next action + // doesn't race the async body replacement and target a stale form. await expect(page.locator(".ingredient-list").filter({ hasText: name })).toBeVisible(); } diff --git a/e2e/tests/meals.spec.ts b/e2e/tests/meals.spec.ts index 3a9fc71..60fd11a 100644 --- a/e2e/tests/meals.spec.ts +++ b/e2e/tests/meals.spec.ts @@ -77,9 +77,7 @@ test("ingredients are grouped under their categories", async ({ page }) => { await createMeal(page, "Spaghetti Bolognese", ""); // Add an ingredient in the default "Produce" category. - await page.fill("#ingredient-name", "Tomato"); - await page.selectOption("#ingredient-category", { label: "Produce" }); - await page.click("#add-ingredient-button"); + await addIngredient(page, "Tomato", "", "Produce"); // Add one without a category. await addIngredient(page, "Penne");