|
1 |
| -const fs = require("fs"); |
2 |
| -const path = require("path"); |
3 |
| -const html = fs.readFileSync(path.resolve(__dirname, "./index.html"), "utf8"); |
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); |
4 | 4 | const css = fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8");
|
| 5 | +document.documentElement.innerHTML = html.toString(); |
5 | 6 |
|
6 |
| -jest.dontMock("fs"); |
| 7 | +jest.dontMock('fs'); |
7 | 8 |
|
8 |
| -describe("All the styles should be applied", function() { |
9 |
| - beforeEach(() => { |
10 |
| - //here I import the HTML into the document |
11 |
| - document.documentElement.innerHTML = html.toString(); |
| 9 | +let cssArray = null; |
12 | 10 |
|
13 |
| - //apply the styles from the stylesheet if needed |
14 |
| - document.querySelector( |
15 |
| - "head" |
16 |
| - ).innerHTML = `<style>${css.toString()}</style>`; |
17 |
| - }); |
18 |
| - afterEach(() => { |
19 |
| - jest.resetModules(); |
20 |
| - }); |
21 |
| - |
22 |
| - it("ul tag should exists", function() { |
| 11 | +describe("All the styles should be applied", ()=>{ |
| 12 | + const icons = document.querySelectorAll("i"); |
| 13 | + test("ul tag should exists", ()=>{ |
23 | 14 | expect(document.querySelector("ul")).toBeTruthy();
|
24 | 15 | });
|
25 |
| - it("At least 3 li tags should exist", function() { |
| 16 | + test("At least 3 li tags should exist", ()=>{ |
26 | 17 | expect(document.querySelectorAll("li").length).toBe(3);
|
27 | 18 | });
|
28 |
| - it("At least 3 i tags should exist", function() { |
| 19 | + test("At least 3 i tags should exist", ()=>{ |
29 | 20 | expect(document.querySelectorAll("i").length).toBe(3);
|
30 | 21 | });
|
31 |
| - it(" LI innerHTML exist", function() { |
| 22 | + test(" LI innerHTML exist", ()=>{ |
32 | 23 | const li = document.querySelectorAll("li");
|
33 | 24 | expect(document.querySelector("li")).toBeTruthy();
|
34 | 25 | for (let i = 0; i < li.length; i++) {
|
35 | 26 | expect(li[i].innerHTML).toBeTruthy();
|
36 | 27 | }
|
37 | 28 | });
|
38 |
| - it('the i tag should have a class "fas"', function() { |
| 29 | + test('the i tag should have a class "fas"', ()=>{ |
39 | 30 | //or use query selector to compare hoy mane scriptags do we have
|
40 |
| - const icon = document.querySelectorAll("i"); |
41 |
| - expect(document.querySelector("i")).toBeTruthy(); |
42 |
| - for (let i = 0; i < icon.length; i++) { |
43 |
| - expect(icon[i].classList.contains("fa")).toBeTruthy(); |
44 |
| - } |
| 31 | + expect(icons).toBeTruthy(); |
| 32 | + |
| 33 | + icons.forEach(icon=>{ |
| 34 | + let hasFas = icon.classList.contains("fas") |
| 35 | + expect(hasFas).toBe(true); |
| 36 | + }) |
45 | 37 | });
|
46 | 38 | });
|
0 commit comments