|
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>`; |
21 | 17 |
|
22 |
| - it("the font-family in the .myTitle should exists", function () { |
23 | 18 | // get computed styles of any element you like
|
24 |
| - let cssArray=document.styleSheets[0].cssRules; |
| 19 | + let cssArray = document.styleSheets[0].cssRules; |
25 | 20 | // 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") { |
29 | 24 | // console.log("%%% ", cssArray[i].selectorText)
|
30 |
| - orangeHoverSelector=cssArray[i].style['font-family']; |
| 25 | + orangeHoverSelector = cssArray[i].style['font-family']; |
31 | 26 | }
|
32 | 27 | }
|
33 | 28 |
|
34 | 29 | expect(orangeHoverSelector).toBeTruthy();
|
35 | 30 | });
|
36 |
| - it('the h1 tag should have a class "myTitle"', function () { |
| 31 | + test('the h1 tag should have a class "myTitle"', ()=>{ |
37 | 32 | //or use query selector to compare hoy mane scriptags do we have
|
38 |
| - const h=document.querySelector("h1"); |
| 33 | + const h = document.querySelector("h1"); |
39 | 34 | expect(h.classList.contains("myTitle")).toBeTruthy();
|
40 | 35 | });
|
41 |
| - it("The link should be included in the head tag", function () { |
| 36 | + test("The link should be included in the head tag", ()=>{ |
42 | 37 | // let headContent=document.getElementsByTagName("*")
|
43 | 38 | // 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); |
46 | 40 | });
|
47 | 41 |
|
48 | 42 |
|
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(); |
51 | 45 | });
|
52 | 46 | });
|
53 | 47 |
|
|
0 commit comments