-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.test.js
28 lines (26 loc) · 1005 Bytes
/
main.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
const { testCases } = require("./test-cases");
const functions = require("./main");
const { setMainDescriber, setMainRunner } = require("./utils");
const testCaseKeys = Object.keys(testCases);
const functionKeys = Object.keys(functions);
try {
for (const k of testCaseKeys) {
if (!functionKeys.includes(k))
throw Error(`No function found for test case '${k}'`);
}
for (const k of functionKeys) {
if (!testCaseKeys.includes(k))
throw Error(`No test case found for function '${k}()'`);
const describer = setMainDescriber(k);
describer(`Unit testing function '${k}()'`, () => {
testCases[k].forEach(([inputs, expected], i) => {
const runner = setMainRunner(k, i);
runner(`\nTest case #${i + 1}: Should output correct value with parameters: \n${inputs.map(inp => JSON.stringify(inp)).join(', ')}`, () => {
expect(functions[k](...inputs)).toStrictEqual(expected);
});
});
});
}
} catch (e) {
console.error(e.message);
}