-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathindex.test.ts
More file actions
35 lines (27 loc) · 1.27 KB
/
index.test.ts
File metadata and controls
35 lines (27 loc) · 1.27 KB
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
import { simpleCalculator, Action } from './index';
describe('simpleCalculator tests', () => {
test('should add two numbers', () => {
expect(simpleCalculator({a: 1, b: 2, action: Action.Add})).toBe(3);
});
//определяет один тест,
//функция Jest, создаёт утверждение (assertion), которое проверяет результат
//сравнивает строго (===) возвращаемое значение с ожидаемым.
test('should subtract two numbers', () => {
expect(simpleCalculator({a:1, b:2, action: Action.Subtract})).toBe(-1);
});
test('should multiply two numbers', () => {
expect(simpleCalculator({a:3, b:2, action: Action.Multiply})).toBe(6);
});
test('should divide two numbers', () => {
expect(simpleCalculator({a:3, b:2, action: Action.Divide})).toBe(1.5);
});
test('should exponentiate two numbers', () => {
expect(simpleCalculator({a:3, b:2, action: Action.Exponentiate})).toBe(9);
});
test('should return null for invalid action', () => {
expect(simpleCalculator({a:3, b:0, action: 'InvalidAction'})).toBeNull();
});
test('should return null for invalid arguments', () => {
expect(simpleCalculator({a:"3", b:1, action: Action.Add})).toBeNull();
});
});