|
| 1 | +import * as fn from '../../src/utils/fn.utils'; |
| 2 | + |
| 3 | +describe('fn.utils - multipurpose functions', () => { |
| 4 | + describe('trim', () => { |
| 5 | + it('returns empty string when input value is null or undefined', () => { |
| 6 | + expect(fn.trim(null)).toEqual(''); |
| 7 | + expect(fn.trim(undefined)).toEqual(''); |
| 8 | + }); |
| 9 | + |
| 10 | + it('uses native trim method under the hood', () => { |
| 11 | + const stringSpy = jasmine.createSpyObj('string', ['trim']); |
| 12 | + stringSpy.trim.and.returnValue('Boo!'); |
| 13 | + expect(fn.trim(stringSpy as string)).toEqual('Boo!'); |
| 14 | + }); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('once', () => { |
| 18 | + it('executes function only ones', () => { |
| 19 | + const onceTargetSpy = jasmine.createSpy('once'); |
| 20 | + const onceExecutableFn = fn.once(onceTargetSpy); |
| 21 | + |
| 22 | + onceExecutableFn('Hello', ', ', 'World'); |
| 23 | + onceExecutableFn('Hello'); |
| 24 | + |
| 25 | + expect(onceTargetSpy).toHaveBeenCalledTimes(1); |
| 26 | + expect(onceTargetSpy).toHaveBeenCalledWith('Hello', ', ', 'World'); |
| 27 | + expect(onceTargetSpy).not.toHaveBeenCalledWith('Hello'); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('defaultsDeep', () => { |
| 32 | + it('uses empty array if there were no sources given', () => { |
| 33 | + const options = fn.defaultsDeep({ msg: 'Boo!' }); |
| 34 | + |
| 35 | + expect(options).toEqual({ msg: 'Boo!' }); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('defaultsDeep', () => { |
| 40 | + it('uses empty array if there were no sources given', () => { |
| 41 | + const options = fn.defaultsDeep({ msg: 'Boo!' }); |
| 42 | + |
| 43 | + expect(options).toEqual({ msg: 'Boo!' }); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('includes', () => { |
| 48 | + it('works with strings', () => { |
| 49 | + expect(fn.includes('world', 'rl')).toEqual(true); |
| 50 | + expect(fn.includes('world', 'rrl')).toEqual(false); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}); |
0 commit comments