-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_unit.js
56 lines (47 loc) · 1.02 KB
/
test_unit.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
"use strict";
import * as App from './example.js';
export {
TestBrowserJS
};
let t_AddSucceed = {
"name": "Add Succeed",
"func": test_AddSuccess,
"golden": true
}
let t_AddFail = {
"name": "Add Fail",
"func": test_AddFail,
"golden": true
}
// Tests Add() for expected successful results.
function test_AddSuccess() {
let sum = App.Add(2, 20);
// See if expected result is what we received.
if (sum !== 22) {
return false;
}
return true;
}
// Tests Add() for expected failure results when not passing a correct type.
function test_AddFail() {
try {
App.Add(2, "20");
} catch (error) {
if (error.message !== "Error: One of the given numbers was not of type number.") {
console.error(error);
return false;
}
return true;
}
return false;
}
/**
* @typedef {import('./test.js').TestsToRun} TestsToRun
* @typedef {import('./test.js').TestBrowserJS} TestBrowserJS
*/
/** @type {TestsToRun}**/
let TestsToRun = [t_AddSucceed, t_AddFail];
/** @type {TestBrowserJS} **/
let TestBrowserJS = {
TestsToRun,
};