-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathutils.spec.ts
63 lines (52 loc) · 1.42 KB
/
utils.spec.ts
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* eslint-disable @typescript-eslint/no-empty-function */
import { isFunction } from '../../../src/components/utils';
function syncFunction(): void {}
async function asyncFunction(): Promise<void> {}
const syncArrowFunction = (): void => {};
const asyncArrowFunction = async (): Promise<void> => {};
describe('isFunction function', () => {
it('should recognise sync functions', () => {
/**
* Act
*/
const commonFunctionResult = isFunction(syncFunction);
const arrowFunctionResult = isFunction(syncArrowFunction);
/**
* Assert
*/
expect(commonFunctionResult).to.eq(true);
expect(arrowFunctionResult).to.eq(true);
});
it('should recognise async functions', () => {
/**
* Act
*/
const commonFunctionResult = isFunction(asyncFunction);
const arrowFunctionResult = isFunction(asyncArrowFunction);
/**
* Assert
*/
expect(commonFunctionResult).to.eq(true);
expect(arrowFunctionResult).to.eq(true);
});
it('should return false if it isn\'t a function', () => {
/**
* Arrange
*/
const obj = {};
const num = 123;
const str = '123';
/**
* Act
*/
const objResult = isFunction(obj);
const numResult = isFunction(num);
const strResult = isFunction(str);
/**
* Assert
*/
expect(objResult).to.eq(false);
expect(numResult).to.eq(false);
expect(strResult).to.eq(false);
});
});