Skip to content

Commit 9bf9768

Browse files
committed
improved tests and cleaned them up
1 parent 13991d0 commit 9bf9768

File tree

1 file changed

+44
-61
lines changed

1 file changed

+44
-61
lines changed
Lines changed: 44 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,90 @@
1-
const fs=require("fs");
2-
const path=require("path");
3-
const html=fs.readFileSync(path.resolve(__dirname, "./index.html"), "utf8");
4-
const css=fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8");
1+
const fs = require('fs');
2+
const path = require('path');
3+
const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8');
4+
const css = fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8");
5+
document.documentElement.innerHTML = html.toString();
56

7+
jest.dontMock('fs');
68

7-
jest.dontMock("fs");
89

910

1011

11-
describe("All the styles should be applied", function () {
12-
beforeEach(() => {
13-
//here I import the HTML into the document
14-
document.documentElement.innerHTML=html.toString();
15-
16-
17-
});
18-
afterEach(() => {
19-
jest.resetModules();
20-
});
21-
22-
it("the padding should be '10px'", function () {
12+
describe("All the styles should be applied", ()=>{
13+
const meta = document.querySelector("meta")
14+
const title = document.querySelector('title')
15+
const link = document.querySelector('link')
16+
test("the padding should be '10px'", ()=>{
2317
document.querySelector(
2418
"head"
2519

26-
).innerHTML=`<style>${css.toString()}</style>`;
27-
let divTag=document.querySelector(".orange-btn");
28-
let classTagStyles=window.getComputedStyle(divTag);
20+
).innerHTML = `<style>${css.toString()}</style>`;
21+
let divTag = document.querySelector(".orange-btn");
22+
let classTagStyles = window.getComputedStyle(divTag);
2923

3024
expect(classTagStyles["padding"]).toBe("10px");
3125
});
32-
it("the border radius should be '4px'", function () {
26+
test("the border radius should be '4px'", ()=>{
3327
document.querySelector(
3428
"head"
3529

36-
).innerHTML=`<style>${css.toString()}</style>`;
37-
let divTag=document.querySelector(".orange-btn");
38-
let classTagStyles=window.getComputedStyle(divTag);
30+
).innerHTML = `<style>${css.toString()}</style>`;
31+
let divTag = document.querySelector(".orange-btn");
32+
let classTagStyles = window.getComputedStyle(divTag);
3933
expect(classTagStyles["border-radius"]).toBe("4px");
4034
});
41-
it("the border should be '1px solid #ffffff;'", function () {
42-
document.querySelector(
43-
"head"
44-
45-
).innerHTML=`<style>${css.toString()}</style>`;
46-
let divTag=document.querySelector(".orange-btn");
47-
let classTagStyles=window.getComputedStyle(divTag);
48-
expect(classTagStyles["border"]).toBe("1px solid #ffffff");
49-
});
50-
it("the background should be 'rgb(255, 153, 51)'", function () {
35+
test("the background should be 'orange'", ()=>{
5136
document.querySelector(
5237
"head"
5338

54-
).innerHTML=`<style>${css.toString()}</style>`;
55-
let divTag=document.querySelector(".orange-btn");
56-
let classTagStyles=window.getComputedStyle(divTag);
39+
).innerHTML = `<style>${css.toString()}</style>`;
40+
let divTag = document.querySelector(".orange-btn");
41+
let classTagStyles = window.getComputedStyle(divTag);
5742
expect(classTagStyles["background"]).toBe("orange");
5843
});
59-
it("the underline should to be removed", function () {
44+
test("the underline should to be removed", ()=>{
6045
document.querySelector(
6146
"head"
6247

63-
).innerHTML=`<style>${css.toString()}</style>`;
64-
let divTag=document.querySelector(".orange-btn");
65-
let classTagStyles=window.getComputedStyle(divTag);
48+
).innerHTML = `<style>${css.toString()}</style>`;
49+
let divTag = document.querySelector(".orange-btn");
50+
let classTagStyles = window.getComputedStyle(divTag);
6651
expect(classTagStyles["text-decoration"]).toBe("none");
6752
});
68-
it("The mouse hover property should be #cc7a00", function () {
53+
test("The mouse hover property should be 'darkorange'", ()=>{
6954
// get computed styles of any element you like
7055
document.querySelector(
7156
"head"
72-
).innerHTML=`<style>${css.toString()}</style>`;
73-
let cssArray=document.styleSheets[0].cssRules;
57+
).innerHTML = `<style>${css.toString()}</style>`;
58+
let cssArray = document.styleSheets[0].cssRules;
7459

75-
let orangeHoverSelector="";
76-
for (let i=0; i<cssArray.length; i++) {
77-
if (cssArray[i].selectorText===".orange-btn:hover") {
78-
orangeHoverSelector=cssArray[i].style.background;
60+
let orangeHoverSelector = "";
61+
for (let i = 0; i < cssArray.length; i++) {
62+
if (cssArray[i].selectorText === ".orange-btn:hover") {
63+
orangeHoverSelector = cssArray[i].style.background;
7964
}
8065
}
8166

8267
expect(orangeHoverSelector).toBe("darkorange");
8368
});
8469

85-
it("You should be careful with the specifity", function () {
70+
test("You should be careful with the specifity", ()=>{
8671
document.querySelector(
8772
"head"
88-
).innerHTML=`<style>${css.toString()}</style>`;
89-
let cssArray=document.styleSheets[0].cssRules[0].selectorText;
73+
).innerHTML = `<style>${css.toString()}</style>`;
74+
let cssArray = document.styleSheets[0].cssRules[0].selectorText;
9075
expect(cssArray).toBe(".orange-btn");
9176
}
9277
)
93-
it("You should not change the existing head tag elements", function () {
78+
test("You should not change the existing head tag elements", ()=>{
9479
let head = document.querySelector('head')
9580
expect(head).toBeTruthy()
96-
97-
let meta = head.querySelector("meta")
98-
expect(meta).not.toBe(null)
99-
100-
const pathname = new URL(document.querySelector('link').href).pathname
101-
expect(pathname).toBe('/styles.css')
102-
103-
let title = head.querySelector('title')
104-
expect(title).not.toBe(null)
81+
82+
expect(meta).toBeTruthy()
83+
84+
let href = link.getAttribute('href')
85+
expect(href).toBe('./styles.css')
86+
87+
expect(title).toBeTruthy()
10588
})
10689

10790
});

0 commit comments

Comments
 (0)