Skip to content

Commit 6cb1212

Browse files
committed
Added project tests
1 parent 6ee7fcc commit 6cb1212

File tree

2 files changed

+138
-2
lines changed

2 files changed

+138
-2
lines changed

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
"description": "",
55
"private": true,
66
"scripts": {
7-
"start": "browser-sync start --server ./src --files ./src"
7+
"start": "browser-sync start --server ./src --files ./src",
8+
"test": "mocha test/*.spec.js"
89
},
910
"author": "Sergio Cruz <[email protected]>",
1011
"license": "MIT",
1112
"devDependencies": {
12-
"browser-sync": "^2.14.0"
13+
"browser-sync": "^2.14.0",
14+
"chai": "^3.5.0",
15+
"jsdom": "^9.4.1",
16+
"mocha": "^3.0.1"
1317
}
1418
}

test/portfolio.spec.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Libraries
2+
const fs = require('fs');
3+
const jsdom = require('jsdom');
4+
const { assert } = require('chai');
5+
6+
// HTML
7+
const srcHtml = fs.readFileSync('./src/index.html');
8+
const doc = jsdom.jsdom(srcHtml);
9+
10+
// Tests
11+
describe('The webpage', () => {
12+
13+
/**
14+
* HEADER
15+
*/
16+
describe('header', () => {
17+
it('should exist', () => {
18+
const header = doc.querySelector('.header');
19+
assert.isOk(header);
20+
});
21+
22+
it('should have a non-empty title', () => {
23+
const h1 = doc.querySelector('.header h1');
24+
assert.isOk(h1);
25+
assert.isOk(h1.textContent);
26+
});
27+
28+
it('should have a non-empty description', () => {
29+
const h2 = doc.querySelector('.header h2');
30+
assert.isOk(h2);
31+
assert.isOk(h2.textContent);
32+
});
33+
});
34+
35+
36+
/**
37+
* TAGLINE
38+
*/
39+
describe('tagline', () => {
40+
it('should exist', () => {
41+
const tagline = doc.querySelector('.tagline');
42+
assert.isOk(tagline);
43+
});
44+
45+
it('should have a non-empty h3 tag', () => {
46+
const h3 = doc.querySelector('.tagline h3');
47+
assert.isOk(h3);
48+
assert.isOk(h3.textContent);
49+
});
50+
51+
it('should have a descriptive paragraph', () => {
52+
const p = doc.querySelector('.tagline p');
53+
assert.isOk(p);
54+
assert.isOk(p.textContent);
55+
});
56+
});
57+
58+
59+
/**
60+
* SKILLS
61+
*/
62+
describe('skills', () => {
63+
it('should exist', () => {
64+
const skills = doc.querySelector('.skills');
65+
assert.isOk(skills);
66+
});
67+
68+
it('should have a non-empty h3 tag', () => {
69+
const h3 = doc.querySelector('.skills h3');
70+
assert.isOk(h3);
71+
assert.isOk(h3.textContent);
72+
});
73+
74+
it('should have a descriptive paragraph', () => {
75+
const p = doc.querySelector('.skills p');
76+
assert.isOk(p);
77+
assert.isOk(p.textContent);
78+
});
79+
80+
it('should have an unordered list of your skills', () => {
81+
const ul = doc.querySelector('.skills ul');
82+
assert.isOk(ul);
83+
});
84+
85+
it('should have at least 3 skills', () => {
86+
const skillItems = doc.querySelectorAll('.skills ul li');
87+
assert.isAtLeast(skillItems.length, 3);
88+
});
89+
90+
it('should have one skill that contains HTML', () => {
91+
const skillItems = Array.from(doc.querySelectorAll('.skills ul li'));
92+
const htmlRegex = /html/i;
93+
94+
const skillsWithHtml = skillItems
95+
.map(li => li.textContent)
96+
.filter(skill => htmlRegex.test(skill));
97+
98+
assert.equal(skillsWithHtml.length, 1);
99+
});
100+
});
101+
102+
103+
/**
104+
* CONTACT
105+
*/
106+
describe('contact', () => {
107+
it('should exist', () => {
108+
const contact = doc.querySelector('.contact');
109+
assert.isOk(contact);
110+
});
111+
112+
it('should have a non-empty h3 tag', () => {
113+
const h3 = doc.querySelector('.contact h3');
114+
assert.isOk(h3);
115+
assert.isOk(h3.textContent);
116+
});
117+
118+
it('should have a descriptive paragraph', () => {
119+
const p = doc.querySelector('.contact p');
120+
assert.isOk(p);
121+
assert.isOk(p.textContent);
122+
});
123+
124+
it('should have a link with an href within the paragraph', () => {
125+
const a = doc.querySelector('.contact p a');
126+
assert.isOk(a);
127+
assert.isOk(a.textContent);
128+
assert.isOk(a.getAttribute('href'));
129+
});
130+
});
131+
132+
});

0 commit comments

Comments
 (0)