tests: fix a flaky test for chives-image
- ID
5038865- date
2026-11-21 08:14:51+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
cdbc0d5- message
tests: fix a flaky test for chives-image Using an `example.com` URL makes this test flaky, because the page will spot the 404 error if it makes the request before the test completes.- changed files
1 file, 10 additions, 3 deletions
Changed files
tests/javascript/test_chives_image.py (9206 → 9397)
diff --git a/tests/javascript/test_chives_image.py b/tests/javascript/test_chives_image.py
index 00ffb08..c531269 100644
--- a/tests/javascript/test_chives_image.py
+++ b/tests/javascript/test_chives_image.py
@@ -108,21 +108,28 @@ def test_set_thumbnail_path(page: Page) -> None:
uses the thumbnail URL.
"""
e = create_image_entity(path="tests/fixtures/media/470906.png")
+
+ # Data URI for a tiny transparent GIF.
+ # See https://stackoverflow.com/a/13139830/1558022
+ thumbnail_path = (
+ "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
+ )
+
page.evaluate(
"""
const elem = document.createElement("chives-image");
elem.imageEntity = %s;
- elem.thumbnailPath = 'https://example.com/thumbnail.png';
+ elem.thumbnailPath = %s;
document.body.appendChild(elem);
"""
- % json.dumps(e),
+ % (json.dumps(e), json.dumps(thumbnail_path)),
)
chives_elem = page.locator("chives-image")
img_elem = chives_elem.locator("img")
expect(img_elem).to_be_visible()
- assert (img_elem).get_attribute("src") == "https://example.com/thumbnail.png"
+ expect(img_elem).to_have_attribute("src", thumbnail_path)
def test_set_href(page: Page) -> None: