From 31b6610e92c9dd95fc57345cb3c05a8902377db2 Mon Sep 17 00:00:00 2001 From: Andrea Verlicchi Date: Tue, 2 Apr 2024 17:51:12 +0200 Subject: [PATCH] Improved readability --- tests/e2e/background_image.spec.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/e2e/background_image.spec.js b/tests/e2e/background_image.spec.js index ee48c6d..6a0768b 100644 --- a/tests/e2e/background_image.spec.js +++ b/tests/e2e/background_image.spec.js @@ -18,22 +18,21 @@ for (const { url, description } of pagesWithSimpleImages) { const element = lazyElements.nth(i); await element.scrollIntoViewIfNeeded(); - // Check the src attribute - const expectedBg = await element.getAttribute("data-bg"); - const expectedHiDpiBg = await element.getAttribute("data-bg-hidpi"); + // Set expectations + const expectedBg = `background-image: url("${await element.getAttribute("data-bg")}");`; + const expectedHiDpiBg = `background-image: url("${await element.getAttribute( + "data-bg-hidpi" + )}");`; if (!expectedHiDpiBg) { - await expect(element).toHaveAttribute("style", `background-image: url("${expectedBg}");`); + await expect(element).toHaveAttribute("style", expectedBg); continue; } - if (devicePixelRatio === 1) { - await expect(element).toHaveAttribute("style", `background-image: url("${expectedBg}");`); + if (devicePixelRatio > 1) { + await expect(element).toHaveAttribute("style", expectedHiDpiBg); } else { - await expect(element).toHaveAttribute( - "style", - `background-image: url("${expectedHiDpiBg}");` - ); + await expect(element).toHaveAttribute("style", expectedBg); } } });