const sum = (a, b) => a + b;
const subtract = (a, b) => a - b;
test('sum', () => {
const result = sum(1, 2);
const expected = 3;
expect(result).toBe(expected);
})
test('subtract', () => {
const result = subtract(1, 2);
const expected = -1;
expect(result).toBe(expected);
})
function test(title, callback) {
try{
callback();
console.log(`%c${title}`, 'color: green');
}
catch(e) {
console.log(`%c${title}`, 'color: red');
console.error(e);
}
}
function expect(actual) {
return {
toBe(expected) {
if(actual !== expected) {
throw new Error(`Expected ${expected}, but got ${actual}`);
}
}
}
}