|
| 1 | +/* eslint-disable @typescript-eslint/no-empty-function */ |
| 2 | +import { isFunction } from '../../../src/components/utils'; |
| 3 | + |
| 4 | +function syncFunction(): void {} |
| 5 | + |
| 6 | +async function asyncFunction(): Promise<void> {} |
| 7 | + |
| 8 | +const syncArrowFunction = (): void => {}; |
| 9 | + |
| 10 | +const asyncArrowFunction = async (): Promise<void> => {}; |
| 11 | + |
| 12 | +describe('isFunction function', () => { |
| 13 | + it('should recognise sync functions', () => { |
| 14 | + /** |
| 15 | + * Act |
| 16 | + */ |
| 17 | + const commonFunctionResult = isFunction(syncFunction); |
| 18 | + const arrowFunctionResult = isFunction(syncArrowFunction); |
| 19 | + |
| 20 | + /** |
| 21 | + * Assert |
| 22 | + */ |
| 23 | + expect(commonFunctionResult).to.eq(true); |
| 24 | + expect(arrowFunctionResult).to.eq(true); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should recognise async functions', () => { |
| 28 | + /** |
| 29 | + * Act |
| 30 | + */ |
| 31 | + const commonFunctionResult = isFunction(asyncFunction); |
| 32 | + const arrowFunctionResult = isFunction(asyncArrowFunction); |
| 33 | + |
| 34 | + /** |
| 35 | + * Assert |
| 36 | + */ |
| 37 | + expect(commonFunctionResult).to.eq(true); |
| 38 | + expect(arrowFunctionResult).to.eq(true); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should return false if it isn\'t a function', () => { |
| 42 | + /** |
| 43 | + * Arrange |
| 44 | + */ |
| 45 | + const obj = {}; |
| 46 | + const num = 123; |
| 47 | + const str = '123'; |
| 48 | + |
| 49 | + /** |
| 50 | + * Act |
| 51 | + */ |
| 52 | + const objResult = isFunction(obj); |
| 53 | + const numResult = isFunction(num); |
| 54 | + const strResult = isFunction(str); |
| 55 | + |
| 56 | + /** |
| 57 | + * Assert |
| 58 | + */ |
| 59 | + expect(objResult).to.eq(false); |
| 60 | + expect(numResult).to.eq(false); |
| 61 | + expect(strResult).to.eq(false); |
| 62 | + }); |
| 63 | +}); |
0 commit comments