Skip to content

Commit e4452cc

Browse files
committed
fixed issue with CSS rules, improved tests
1 parent b512f71 commit e4452cc

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

exercises/10-Your-Own-Font/tests.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,47 @@
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-
6-
jest.dontMock("fs");
7-
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-
// document.querySelector(
15-
// "head"
16-
// ).innerHTML=`<style>${css.toString()}</style>`;
17-
});
18-
afterEach(() => {
19-
jest.resetModules();
20-
});
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();
6+
7+
jest.dontMock('fs');
8+
9+
let cssArray = null;
10+
11+
describe("All the styles should be applied", ()=>{
12+
const link = document.querySelectorAll("link")
13+
test("the font-family in the .myTitle should exists", ()=>{
14+
document.querySelector(
15+
"head"
16+
).innerHTML = `<style>${css.toString()}</style>`;
2117

22-
it("the font-family in the .myTitle should exists", function () {
2318
// get computed styles of any element you like
24-
let cssArray=document.styleSheets[0].cssRules;
19+
let cssArray = document.styleSheets[0].cssRules;
2520
// console.log("%%% ", cssArray)
26-
let orangeHoverSelector="";
27-
for (let i=0; i<cssArray.length; i++) {
28-
if (cssArray[i].selectorText===".myTitle") {
21+
let orangeHoverSelector = "";
22+
for (let i = 0; i < cssArray.length; i++) {
23+
if (cssArray[i].selectorText === ".myTitle") {
2924
// console.log("%%% ", cssArray[i].selectorText)
30-
orangeHoverSelector=cssArray[i].style['font-family'];
25+
orangeHoverSelector = cssArray[i].style['font-family'];
3126
}
3227
}
3328

3429
expect(orangeHoverSelector).toBeTruthy();
3530
});
36-
it('the h1 tag should have a class "myTitle"', function () {
31+
test('the h1 tag should have a class "myTitle"', ()=>{
3732
//or use query selector to compare hoy mane scriptags do we have
38-
const h=document.querySelector("h1");
33+
const h = document.querySelector("h1");
3934
expect(h.classList.contains("myTitle")).toBeTruthy();
4035
});
41-
it("The link should be included in the head tag", function () {
36+
test("The link should be included in the head tag", ()=>{
4237
// let headContent=document.getElementsByTagName("*")
4338
// console.log("###", headContent[1].innerHTML)
44-
console.log("###", document.head.childNodes)
45-
expect(document.querySelectorAll("link").length).toBe(2);
39+
expect(link.length).toBe(2);
4640
});
4741

4842

49-
it("The Head tag should not includes a Style tag", function () {
50-
expect(html.toString().indexOf(`<style`)>-1).toBeFalsy();
43+
test("The Head tag should not includes a Style tag", ()=>{
44+
expect(html.toString().indexOf(`<style`) > -1).toBeFalsy();
5145
});
5246
});
5347

0 commit comments

Comments
 (0)