Слайд 2
Задачка export function MyCustomAbs(x: number): number {
return
x < 0 ? -x : x;
}
Слайд 3
Обложим тестами describe('MyCustomAbs', () => {
for (let
x = -3; x < 3; x++) {
let expected = Math.abs(x);
it(`should return ${expected} for ${x}`, () => {
expect(MyCustomAbs(x)).toBe(expected);
});
}
});
Слайд 4
Результат Started ...... 6 specs, 0 failures Finished in 0.006 seconds
Слайд 5
Вроде все хорошо… или нет? Started
.........F..
Failures:
1) 1 / MyCustomAbs(x)
should return expected equal input for 0
Message:
Expected false to be true.
Stack:
Error: Expected false to be true.
at Object. (X:\var\node\test\math-tests\spec\index.spec.js:18:61)
12 specs, 1 failure
Finished in 0.006 seconds