forked from hryanjones/guess-my-word
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
41 lines (35 loc) · 1.49 KB
/
tests.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
testGetFormattedTime();
testNoDuplicatesInWordList();
testThatDifficultyMatchesDropdownWhenStartGuessing();
function testGetFormattedTime() {
const start = new Date('2000-01-01T00:00:00');
getFormattedTime(start, start) === '0s' || oops();
getFormattedTime(start, new Date('2000-01-01T00:00:03')) === '3s' || oops();
getFormattedTime(start, new Date('2000-01-01T00:00:10')) === '10s' || oops();
getFormattedTime(start, new Date('2000-01-01T00:27:01')) === '27m 1s' || oops();
getFormattedTime(start, new Date('2000-01-01T00:46:59')) === '46m 59s' || oops();
getFormattedTime(start, new Date('2000-01-01T01:02:45')) === '1h 2m 45s' || oops();
getFormattedTime(start, new Date('2000-01-01T23:19:08')) === '23h 19m 8s' || oops();
}
function testNoDuplicatesInWordList() {
const wordsSeenBefore = new Set();
for (const wordListKey in possibleWords) {
possibleWords[wordListKey].forEach(newPossibleWord => {
if (newPossibleWord && wordsSeenBefore.has(newPossibleWord)) {
oops(newPossibleWord);
}
wordsSeenBefore.add(newPossibleWord);
});
}
}
function testThatDifficultyMatchesDropdownWhenStartGuessing() {
getDifficultyChanger().value = 'hard';
getInput().value = 'guess';
document.getElementById('submit-guess').click();
if (difficulty !== 'hard') {
oops('expected difficulty to match dropdown');
}
}
function oops(didNotExpect = '') {
throw new Error(`oops: ${didNotExpect}`);
}