This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
77 lines (64 loc) · 4.48 KB
/
test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(function() {
'use strict';
setTimeout(function() {
try {
var root = document.getElementById('mocha');
var testResults = document.getElementById('test-results');
assertEqual(root.innerHTML.length > 0, true, 'rendered something');
var screen = root.firstChild;
assertEqual(screen.style.whiteSpace, 'pre-wrap', 'screen has the appropriate white-space wrapping');
assertEqual(screen.style.wordWrap, 'break-word', 'screen wraps the long line of dots and Fs');
var firstResult = root.querySelector('pre:nth-child(1)>code:nth-child(1)');
assertEqual(toString(firstResult), '[object HTMLElement]', 'first result is rendered');
assertEqual(firstResult.className, 'success', 'first result is a success');
assertEqual(firstResult.textContent, '.', 'first result renders a dot');
assertEqual(firstResult.title, 'tests this one will pass', 'first result’s dot has the appropriate title');
var secondResult = root.querySelector('pre:nth-child(1)>code:nth-child(2)');
assertEqual(toString(secondResult), '[object HTMLElement]', 'second result is rendered');
assertEqual(secondResult.className, 'failure', 'second result is a success');
assertEqual(secondResult.textContent, 'F', 'second result renders an F');
assertEqual(secondResult.title,
'tests this one will fail: this is a long assertion failure message ' +
'that should come out in the failure details section and should wrap: ' +
'expected true to equal false',
'second result’s F has the appropriate title');
var thirdResult = root.querySelector('pre:nth-child(1)>code:nth-child(3)');
assertEqual(toString(thirdResult), '[object HTMLElement]', 'third result is rendered');
assertEqual(thirdResult.className, 'success', 'third result is a success');
assertEqual(thirdResult.textContent, '.', 'third result renders a dot');
assertEqual(thirdResult.title, 'tests this one will pass too', 'third result’s dot has the appropriate title');
var fourthResult = root.querySelector('pre:nth-child(1)>code:nth-child(4)');
assertEqual(toString(fourthResult), '[object HTMLElement]', 'fourth result is rendered');
assertEqual(fourthResult.className, 'pending', 'fourth result is a pending test');
assertEqual(fourthResult.textContent, '*', 'fourth result renders an asterisk');
assertEqual(fourthResult.title, 'tests a pending test', 'fourth result’s asterisk has the appropriate title');
var summary = root.querySelector('pre:nth-child(1)>code:nth-child(5)');
assertEqual(toString(summary), '[object HTMLElement]', 'summary is rendered');
assertEqual(summary.className, 'end', 'fourth thing is the summary');
assertEqual(summary.textContent.trim(), '2 of 3 passed, 1 pending', 'summary tells how many of how many passed');
assertEqual(summary.querySelectorAll('.number').length, 3, 'summary emphasizes the number');
var failureDetails = root.querySelector('pre:nth-child(2)>pre:nth-child(1)');
assertEqual(toString(failureDetails), '[object HTMLPreElement]', 'failure details are rendered');
assertEqual(failureDetails.className, 'failure-detail', 'failure details have the appropriate class');
assertEqual(failureDetails.style.whiteSpace, 'pre-line', 'wrap the assertion failure message');
assertEqual(failureDetails.textContent, 'tests this one will fail:\n' +
'AssertionError: this is a long assertion failure message that should come out in the ' +
'failure details section and should wrap: expected true to equal false\n' +
' at Context.<anonymous> (sample-tests.js:10:23)',
'prints the failure details');
var duration = root.querySelector('pre:nth-child(3)');
assertEqual(toString(duration), '[object HTMLPreElement]', 'duration report is rendered');
assertEqual(duration.textContent.length > 0, true, 'duration report has some text');
assertEqual(/test run time: \d+.\d{1,3}s/.test(duration.textContent), true, 'duration report looks like a number of seconds');
} catch (error) {
testResults.innerHTML += '\n<strong>FAILED: ' + error.message + '</strong>';
}
function assertEqual(actual, expected, message) {
if (actual === expected) testResults.innerHTML += '\nPASSED: ' + message;
else throw new Error(message + '.\n\texpected: ' + expected + '\n\tactual: ' + actual);
}
function toString(thing) {
return Object.prototype.toString.apply(thing);
}
});
}());