@@ -6,30 +6,6 @@ const css = fs.readFileSync(path.resolve(__dirname, './styles.css'), 'utf8');
6
6
7
7
jest . dontMock ( 'fs' ) ;
8
8
9
- describe ( 'All the javascript should match' , function ( ) {
10
- beforeEach ( ( ) => {
11
- //here I import the HTML into the document
12
- document . documentElement . innerHTML = html . toString ( ) ;
13
- } ) ;
14
- afterEach ( ( ) => { jest . resetModules ( ) ; } ) ;
15
-
16
- it ( 'alert() function should be called' , function ( ) {
17
-
18
- /*
19
- Here is how to mock the alert function:
20
- https://stackoverflow.com/questions/41885841/how-to-mock-the-javascript-window-object-using-jest
21
- */
22
- global . alert = jest . fn ( ( text ) => console . log ( text ) ) ;
23
-
24
- //then I import the index.js (which should have the alert() call inside)
25
- const file = require ( "./index.js" ) ;
26
-
27
- //and I expect the alert to be already called.
28
- expect ( alert . mock . calls . length ) . toBe ( 1 ) ;
29
- } ) ;
30
- } ) ;
31
-
32
-
33
9
describe ( 'All the styles should be applied' , function ( ) {
34
10
beforeEach ( ( ) => {
35
11
//here I import the HTML into the document
@@ -57,14 +33,22 @@ describe('All the html should match', function () {
57
33
} ) ;
58
34
afterEach ( ( ) => { jest . resetModules ( ) ; } ) ;
59
35
60
- it ( 'the html code should contain a script tag' , function ( ) {
36
+ it ( 'the html code should contain a p tag' , function ( ) {
61
37
62
38
// we can read from the source code
63
39
console . log ( html . toString ( ) ) ;
64
- expect ( html . toString ( ) . indexOf ( `<script src="./index.js"></script>` ) > - 1 ) . toBeTruthy ( ) ;
40
+ expect ( html . toString ( ) . indexOf ( `<p` ) > - 1 ) . toBeTruthy ( ) ;
41
+
42
+ //or use query selector to compare hoy mane scriptags do we have
43
+ const pTags = document . querySelectorAll ( "p" ) ;
44
+ expect ( pTags . length ) . toBe ( 1 ) ;
45
+ } ) ;
46
+
47
+
48
+ it ( 'the p tag should have a class "big"' , function ( ) {
65
49
66
50
//or use query selector to compare hoy mane scriptags do we have
67
- const scripts = document . querySelectorAll ( "script ") ;
68
- expect ( scripts . length ) . toBe ( 1 ) ;
51
+ const p = document . querySelector ( "p ") ;
52
+ expect ( p . classList . contains ( "big" ) ) . toBeTruthy ( ) ;
69
53
} ) ;
70
54
} ) ;
0 commit comments