|
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(); |
5 | 6 |
|
6 |
| -jest.dontMock("fs"); |
| 7 | +jest.dontMock('fs'); |
7 | 8 |
|
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", ()=>{ |
21 | 14 | // get computed styles of any element you like
|
22 | 15 | document.querySelector(
|
23 | 16 | "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); |
27 | 20 | expect(styles["font-size"]).toBe("0.8em");
|
28 | 21 | });
|
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", ()=>{ |
30 | 23 | // get computed styles of any element you like
|
31 | 24 | document.querySelector(
|
32 | 25 | "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); |
36 | 29 | expect(styles["font-size"]).toBe("0.8rem");
|
37 | 30 | });
|
38 |
| - it("You should add your rules below the existing code", function () { |
| 31 | + test("You should add your rules below the existing code", ()=>{ |
39 | 32 | document.querySelector(
|
40 | 33 | "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; |
43 | 36 |
|
44 | 37 | expect(cssArray).toBe("#my-first-div");
|
45 | 38 | }
|
46 | 39 | )
|
47 |
| - it("You should add your rules below the existing code", function () { |
| 40 | + test("You should add your rules below the existing code", ()=>{ |
48 | 41 | document.querySelector(
|
49 | 42 | "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; |
52 | 45 | expect(cssArray).toBe("#the-second-one");
|
53 | 46 | }
|
54 | 47 | )
|
55 |
| - it("You should not change the existing head tag elements", function () { |
| 48 | + test("You should not change the existing head tag elements", ()=>{ |
56 | 49 | let head = document.querySelector('head')
|
57 | 50 | 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() |
67 | 58 | })
|
68 | 59 |
|
69 | 60 | });
|
0 commit comments