-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy path16.testing.js
45 lines (37 loc) · 916 Bytes
/
16.testing.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
const assert = require('assert');
function sum(a, b) {
return a + b;
}
assert.equal(sum(1, 1), 2);
assert.equal(sum(0, 1), 1);
assert.equal(sum(1, 1), 2);
function numberOrZero(x) {
if (isNaN(x)) {
return 0;
}
return Number(x);
}
assert.equal(numberOrZero(1), 1);
assert.equal(numberOrZero(2), 2);
assert.equal(numberOrZero(null), 0);
assert.equal(numberOrZero("any_string"), 0);
assert.equal(numberOrZero(), 0);
function canAccessToCasino(person) {
if (!person || !person.age || person.age < 18) {
throw new Error("cannot access!");
}
return true;
}
let sut = () => {
canAccessToCasino();
};
assert.throws(sut, /cannot access!/);
sut = () => {
canAccessToCasino({name: "Joe"});
};
assert.throws(sut, /cannot access!/);
sut = () => {
canAccessToCasino({name: "Joe", age: 17});
};
assert.throws(sut, /cannot access!/);
assert.equal(canAccessToCasino({name: "Ian", age: 18}), true);