Skip to content

Commit cb10a77

Browse files
committed
fixed and cleaned up tests
1 parent 247b554 commit cb10a77

File tree

1 file changed

+32
-41
lines changed
  • exercises/12-Relative-Length-EM-REM

1 file changed

+32
-41
lines changed
Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,60 @@
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

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();
12-
13-
//apply the styles from the stylesheet if needed
14-
15-
});
16-
afterEach(() => {
17-
jest.resetModules();
18-
});
19-
20-
it("The H2 Tag should have a font-size: 0.8em", function () {
9+
describe("All the styles should be applied", ()=>{
10+
const meta = document.querySelector("meta")
11+
const title = document.querySelector('title')
12+
const link = document.querySelector('link')
13+
test("The H2 Tag should have a font-size: 0.8em", ()=>{
2114
// get computed styles of any element you like
2215
document.querySelector(
2316
"head"
24-
).innerHTML=`<style>${css.toString()}</style>`;
25-
const h2Tag=document.querySelector("h2");
26-
var styles=window.getComputedStyle(h2Tag);
17+
).innerHTML = `<style>${css.toString()}</style>`;
18+
const h2Tag = document.querySelector("h2");
19+
var styles = window.getComputedStyle(h2Tag);
2720
expect(styles["font-size"]).toBe("0.8em");
2821
});
29-
it("The H3 Tag should haave a font-size: 0.8rem", function () {
22+
test("The H3 Tag should haave a font-size: 0.8rem", ()=>{
3023
// get computed styles of any element you like
3124
document.querySelector(
3225
"head"
33-
).innerHTML=`<style>${css.toString()}</style>`;
34-
const h3Tag=document.querySelector("h3");
35-
var styles=window.getComputedStyle(h3Tag);
26+
).innerHTML = `<style>${css.toString()}</style>`;
27+
const h3Tag = document.querySelector("h3");
28+
var styles = window.getComputedStyle(h3Tag);
3629
expect(styles["font-size"]).toBe("0.8rem");
3730
});
38-
it("You should add your rules below the existing code", function () {
31+
test("You should add your rules below the existing code", ()=>{
3932
document.querySelector(
4033
"head"
41-
).innerHTML=`<style>${css.toString()}</style>`;
42-
let cssArray=document.styleSheets[0].cssRules[0].selectorText;
34+
).innerHTML = `<style>${css.toString()}</style>`;
35+
let cssArray = document.styleSheets[0].cssRules[0].selectorText;
4336

4437
expect(cssArray).toBe("#my-first-div");
4538
}
4639
)
47-
it("You should add your rules below the existing code", function () {
40+
test("You should add your rules below the existing code", ()=>{
4841
document.querySelector(
4942
"head"
50-
).innerHTML=`<style>${css.toString()}</style>`;
51-
let cssArray=document.styleSheets[0].cssRules[1].selectorText;
43+
).innerHTML = `<style>${css.toString()}</style>`;
44+
let cssArray = document.styleSheets[0].cssRules[1].selectorText;
5245
expect(cssArray).toBe("#the-second-one");
5346
}
5447
)
55-
it("You should not change the existing head tag elements", function () {
48+
test("You should not change the existing head tag elements", ()=>{
5649
let head = document.querySelector('head')
5750
expect(head).toBeTruthy()
58-
59-
let meta = head.querySelector("meta")
60-
expect(meta).not.toBe(null)
61-
62-
const pathname = new URL(document.querySelector('link').href).pathname
63-
expect(pathname).toBe('/styles.css')
64-
65-
let title = head.querySelector('title')
66-
expect(title).not.toBe(null)
51+
52+
expect(meta).toBeTruthy()
53+
54+
let href = link.getAttribute('href')
55+
expect(href).toBe('./styles.css')
56+
57+
expect(title).toBeTruthy()
6758
})
6859

6960
});

0 commit comments

Comments
 (0)