<!-- Use a descriptive title, prefix it with [FIX], [FEATURE] or [ENHANCEMENT] if applicable (use only one) --> ## Description <!-- Write a detailed description of your changes/additions here --> Adding a snippet to fetch all images from within a desired element. <!-- If your PR resolves an issue, please state "Resolves #(issue number)" to help maintainers process it faster --> <!-- If you think your PR will cause breaking changes, require changes in the documentation etc, please be so kind as to explain what, where and how --> ## PR Type - [x] Snippets, Tests & Tags (new snippets, updated snippets, re-tagging of snippets, added/updated tests) - [ ] Scripts & Website & Meta (anything related to files in the [scripts folder](https://github.com/30-seconds/30-seconds-of-code/tree/master/scripts), how the repository's automated procedures work and the website) - [ ] Glossary & Secondary Features (anything related to the glossary, such as new or updated terms or other secondary features) - [ ] General, Typos, Misc. & Meta (everything else, typos, general stuff and meta files in the repository - e.g. the issue template) ## Guidelines - [x] I have read the guidelines in the [CONTRIBUTING](https://github.com/30-seconds/30-seconds-of-code/blob/master/CONTRIBUTING.md) document.
19 lines
778 B
JavaScript
19 lines
778 B
JavaScript
const expect = require("expect");
|
|
const getImages = require("./getImages.js");
|
|
const jsdom = require("jsdom");
|
|
const { JSDOM } = jsdom;
|
|
const TEST_HTML = new JSDOM("<!DOCTYPE html><p>Hello world</p><img src=\"https://upload.wikimedia.org/wikipedia/en/1/12/Yellow_Smiley_Face.png\"></img>").window.document;
|
|
|
|
test("getImages is a Function", () => {
|
|
expect(getImages).toBeInstanceOf(Function);
|
|
});
|
|
|
|
test("getImages returns an Array", () => {
|
|
expect(getImages(TEST_HTML)).toBeInstanceOf(Array);
|
|
});
|
|
|
|
test("getImages removes duplicates from images Array", () => {
|
|
expect(getImages(TEST_HTML, false).length).toBeLessThanOrEqual(getImages(TEST_HTML, true).length);
|
|
expect(getImages(TEST_HTML, true)).toEqual(expect.arrayContaining(getImages(TEST_HTML, false)));
|
|
});\n
|