mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
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:
+20
-1
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user