fix(curriculum): Make recipe page test for invalid image URLs (#59338)

Co-authored-by: Ilenia <26656284+ilenia-magoni@users.noreply.github.com>
This commit is contained in:
c0d1ng_ma5ter
2025-03-21 17:14:00 -06:00
committed by GitHub
parent bd8231572d
commit 52cf40d5d0
@@ -147,7 +147,26 @@ assert.exists(document.querySelector('img'));
All your `img` elements should have a valid `src` attribute and value.
```js
assert.isAbove(document.querySelector('img')?.src.length, 0);
const img = document.querySelector('img');
const rawSrc = img?.getAttribute('src');
const resolvedSrc = img?.src;
const re = new RegExp(window.location.href, "ig");
assert.isAbove(rawSrc?.trim().length, 0, "The 'src' attribute must be explicitly set.");
assert.notMatch(resolvedSrc, re, "The 'src' should not start with the current page URL");
img.onload = () => {
console.log('Image loaded successfully.');
};
img.onerror = (error) => {
console.error('Image failed to load:', error);
assert.fail("Your image's URL should be valid."); // Make the test instafail
};
if (img.complete) {
img.onload && img.onload();
};
```
All your `img` elements should have an `alt` attribute to describe the image.