/
load-web-page.spec.js
57 lines (44 loc) 路 2.11 KB
/
load-web-page.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Mocha Specification Suite
// Imports
import { assertDeepStrictEqual } from 'assert-deep-strict-equal';
import { serverListening } from '../dist/server-listening.js';
// Setup
const url = 'https://pretty-print-json.js.org/';
let web; //fields: url, dom, window, document, title, html, verbose
describe('Load Web Page specification', () => {
before(() => serverListening.loadWebPage(url).then(webInst => web = webInst));
after(() => serverListening.closeWebPage(web));
/////////////////////////////////////////////////////////////////////////////////////
describe('The web page', () => {
const getTags = (elems) => [...elems].map(elem => elem.nodeName.toLowerCase());
it('has the correct URL', () => {
const actual = { url: web.window.location.href };
const expected = { url: url };
assertDeepStrictEqual(actual, expected);
});
it('title starts with "Pretty-Print JSON"', () => {
const actual = { title: web.title.substring(0, 'Pretty-Print JSON'.length) };
const expected = { title: 'Pretty-Print JSON' };
assertDeepStrictEqual(actual, expected);
});
it('body has exactly one header, main, and footer -- body.children', () => {
const actual = getTags(web.document.body.children);
const expected = ['header', 'main', 'footer'];
assertDeepStrictEqual(actual, expected);
});
it('body has exactly one header, main, and footer -- querySelectorAll()', () => {
const actual = getTags(web.document.querySelectorAll('body >*'));
const expected = ['header', 'main', 'footer'];
assertDeepStrictEqual(actual, expected);
});
});
/////////////////////////////////////////////////////////////////////////////////////
describe('The document content', () => {
it('has a 馃殌 traveling to 馃獝!', () => {
const actual = { '馃殌': !!web.html.match(/馃殌/g), '馃獝': !!web.html.match(/馃獝/g) };
const expected = { '馃殌': true, '馃獝': true };
assertDeepStrictEqual(actual, expected);
});
});
////////////////////////////////////////////////////////////////////////////////
});