-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassertion-library.js
62 lines (54 loc) · 1.44 KB
/
assertion-library.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
const {sum, subtract} = require('./math')
function sumTest() {
const result = sum(3, 7)
const expected = 10
expect(result).toBe(expected)
}
test('test sum numbers', sumTest)
function subtractTest() {
const result = subtract(7, 3)
const expected = 4
expect(result).toBe(expected)
}
test('test subtract numbers', subtractTest)
function subtractZero() {
result = subtract(0, 5)
expected = 0
expect(result).toBeGreaterThan(expected)
}
test('test if Negative numbers exist from subtraction', subtractZero)
/* Practice using arrow functions */
test('Test Sum Numbers Arrow', () => {
const result = sum(3, 7)
const expected = 10
expect(result).toBe(expected)
})
/* Pracice understanding Async */
test('Testing Async Sum Numbers', async () => {
const result = await sum(3, 7, 4)
const expected = 14
expect(result).toBe(expected)
})
async function test(title, callback) {
try {
await callback()
console.log(`✓ ${title}`)
} catch (error) {
console.error(`✗ ${title}`)
console.error(error)
}
}
function expect(actual){
return {
toBe(expected) {
if(actual !== expected) {
throw new Error(`${actual} is not equal to ${expected}`)
}
},
toBeGreaterThan(expected) {
if(actual >= expected) {
throw new Error(`${actual} is greater than ${expected}`)
}
}
}
}