Skip to content

Commit b62745c

Browse files
committed
fixed test checking for the wrong class, improved tests overall
1 parent a01e4bf commit b62745c

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed
Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
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');
44
const css = fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8");
5+
document.documentElement.innerHTML = html.toString();
56

6-
jest.dontMock("fs");
7+
jest.dontMock('fs');
78

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;
1210

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", ()=>{
2314
expect(document.querySelector("ul")).toBeTruthy();
2415
});
25-
it("At least 3 li tags should exist", function() {
16+
test("At least 3 li tags should exist", ()=>{
2617
expect(document.querySelectorAll("li").length).toBe(3);
2718
});
28-
it("At least 3 i tags should exist", function() {
19+
test("At least 3 i tags should exist", ()=>{
2920
expect(document.querySelectorAll("i").length).toBe(3);
3021
});
31-
it(" LI innerHTML exist", function() {
22+
test(" LI innerHTML exist", ()=>{
3223
const li = document.querySelectorAll("li");
3324
expect(document.querySelector("li")).toBeTruthy();
3425
for (let i = 0; i < li.length; i++) {
3526
expect(li[i].innerHTML).toBeTruthy();
3627
}
3728
});
38-
it('the i tag should have a class "fas"', function() {
29+
test('the i tag should have a class "fas"', ()=>{
3930
//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+
})
4537
});
4638
});

0 commit comments

Comments
 (0)