Skip to content

Commit a9602bb

Browse files
committed
first example
1 parent 17aec36 commit a9602bb

File tree

4 files changed

+15
-33
lines changed

4 files changed

+15
-33
lines changed

exercises/00-Welcome/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Welcome!!
22

3-
Here are the DOM Excercises
3+
Here are the CSS Excercises

exercises/01-hello-world/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
<link rel="stylesheet" type="text/css" href="./styles.css" />
77
</head>
88
<body>
9-
<h1 id="theTitle">Hello world title</h1>
10-
<p>
9+
<p class="big">
1110
This is my description, it needs to be long because is supposed to be a
1211
paragraph and not a title.
1312
</p>
14-
<script src="./index.js"></script>
1513
</body>
1614
</html>

exercises/01-hello-world/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
alert("Hello world!!");
1+
//nothing to see here

exercises/01-hello-world/tests.js

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,6 @@ const css = fs.readFileSync(path.resolve(__dirname, './styles.css'), 'utf8');
66

77
jest.dontMock('fs');
88

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-
339
describe('All the styles should be applied', function () {
3410
beforeEach(() => {
3511
//here I import the HTML into the document
@@ -57,14 +33,22 @@ describe('All the html should match', function () {
5733
});
5834
afterEach(() => { jest.resetModules(); });
5935

60-
it('the html code should contain a script tag', function () {
36+
it('the html code should contain a p tag', function () {
6137

6238
// we can read from the source code
6339
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 () {
6549

6650
//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();
6953
});
7054
});

0 commit comments

Comments
 (0)