From 3bf4f0275af4f2b3f75e52522cd3a7d8c5c91f85 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Sat, 29 Nov 2025 16:59:17 +0100 Subject: [PATCH] chore(e2e): use expect().toBeCloseTo instead of Math.round (#10257) Followup to https://codeberg.org/forgejo/forgejo/pulls/6799, https://codeberg.org/forgejo/forgejo/pulls/9057 toBeCloseTo() recently popped in autocomplete suggestions and it seems like a cleaner way than using Math.round Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10257 Reviewed-by: Otto Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org> --- tests/e2e/switch.test.e2e.ts | 3 +-- tests/e2e/user-cards.test.e2e.ts | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/e2e/switch.test.e2e.ts b/tests/e2e/switch.test.e2e.ts index 6c7b33bbf6..2a42612dc4 100644 --- a/tests/e2e/switch.test.e2e.ts +++ b/tests/e2e/switch.test.e2e.ts @@ -70,6 +70,5 @@ test('Switch CSS properties', async ({browser}) => { // E2E already runs clients with both fine and coarse pointer simulated // This test will verify that coarse-related CSS is working as intended const itemHeight = await page.evaluate(() => window.matchMedia('(pointer: coarse)').matches) ? 38 : 34; - // In Firefox Math.round is needed because .height is 33.99998474121094 - expect(Math.round((await page.locator('#issue-filters .switch > .item:nth-child(1)').boundingBox()).height)).toBe(itemHeight); + expect((await page.locator('#issue-filters .switch > .item:nth-child(1)').boundingBox()).height).toBeCloseTo(itemHeight); }); diff --git a/tests/e2e/user-cards.test.e2e.ts b/tests/e2e/user-cards.test.e2e.ts index 22c31965d6..3d1989493f 100644 --- a/tests/e2e/user-cards.test.e2e.ts +++ b/tests/e2e/user-cards.test.e2e.ts @@ -20,10 +20,10 @@ test('Usercards width', async ({page}) => { for (let i = 1; i <= amount; i++) { const card = await page.locator(`.user-cards .card:nth-child(${i})`).boundingBox(); - widths.push(Math.round(card.width)); + widths.push(card.width); } for (const width of widths) { - expect(width).toBe(widths[0]); + expect(width).toBeCloseTo(widths[0], 0); } });