-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathifElse.test.js
More file actions
46 lines (35 loc) · 1.19 KB
/
ifElse.test.js
File metadata and controls
46 lines (35 loc) · 1.19 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
36
37
38
39
40
41
42
43
44
45
'use strict';
const { ifElse } = require('./ifElse');
describe('ifElse', () => {
let firstMock;
let secondMock;
let conditionTrue;
let conditionFalse;
beforeEach(() => {
firstMock = jest.fn();
secondMock = jest.fn();
conditionTrue = () => true;
conditionFalse = () => false;
});
it('should call first callback if condition returns true', () => {
ifElse(conditionTrue, firstMock, secondMock);
expect(firstMock).toHaveBeenCalled();
expect(secondMock).not.toHaveBeenCalled();
});
it('should call second callback if condition returns false', () => {
ifElse(conditionFalse, firstMock, secondMock);
expect(secondMock).toHaveBeenCalled();
expect(firstMock).not.toHaveBeenCalled();
});
it('should work when condition is a dynamic function', () => {
const dynamicCondition = jest.fn(() => true);
ifElse(dynamicCondition, firstMock, secondMock);
expect(dynamicCondition).toHaveBeenCalled();
expect(firstMock).toHaveBeenCalled();
expect(secondMock).not.toHaveBeenCalled();
});
it('should not return any value', () => {
const result = ifElse(conditionTrue, firstMock, secondMock);
expect(result).toBeUndefined();
});
});