-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTestHelper.js
More file actions
41 lines (36 loc) · 830 Bytes
/
TestHelper.js
File metadata and controls
41 lines (36 loc) · 830 Bytes
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
// @params: { String: title, Function: callback }
function test(title, callback) {
try {
callback();
console.log(`✅ ${title}`);
} catch (error) {
console.log(`❌ ${title}`);
console.log('Error', error);
}
}
function assert(result) {
return {
toBe: function (expected) {
if (result !== expected) {
throw new Error(`Expected ${expected}. Received ${result}`);
}
},
};
}
module.exports = { test, assert };
// NOTE: The only assertion right now is:
// * toBe
// HOW TO USE:
// 1. Define your assertions.
/*
const result = add(10, 1);
const expected = 11;
*/
// 2. Call the test function:
/*
test('Should be able to add two positive integers', function addTwoPositiveInt() {
const result = add(10, 1);
const expected = 11;
assert(result).toBe(expected);
});
*/