|
| 1 | +import { removeUndefinedElements } from '../../src/utils'; |
| 2 | + |
| 3 | +describe('Utils: removeUndefinedElements', () => { |
| 4 | + it('should return empty object for empty object', () => { |
| 5 | + const originalObject: {} = {}; |
| 6 | + const expectedObject: {} = {}; |
| 7 | + |
| 8 | + const actualObject = removeUndefinedElements(originalObject); |
| 9 | + |
| 10 | + expect(actualObject).toEqual(expectedObject); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should return empty array for empty array', () => { |
| 14 | + const originalArray: [] = []; |
| 15 | + const expectedArray: [] = []; |
| 16 | + |
| 17 | + const actualArray = removeUndefinedElements(originalArray); |
| 18 | + |
| 19 | + expect(actualArray).toEqual(expectedArray); |
| 20 | + }); |
| 21 | + |
| 22 | + it('shouldn\'t remove any element', () => { |
| 23 | + const originalObject = { |
| 24 | + key1: 'stringValue', |
| 25 | + emptyString: '', |
| 26 | + nullValue: null, |
| 27 | + falseBooleanValue: false, |
| 28 | + trueBooleanValue: true, |
| 29 | + map: new Map(), |
| 30 | + set: new Set(), |
| 31 | + emptyArray: [], |
| 32 | + number: 0, |
| 33 | + arrayWithNullElements: [null, null], |
| 34 | + arrayWithEmptyString: [''], |
| 35 | + arrayWithStrings: ['string1', 'string2'], |
| 36 | + }; |
| 37 | + |
| 38 | + const expectedObject = { |
| 39 | + key1: 'stringValue', |
| 40 | + emptyString: '', |
| 41 | + nullValue: null, |
| 42 | + falseBooleanValue: false, |
| 43 | + trueBooleanValue: true, |
| 44 | + map: new Map(), |
| 45 | + set: new Set(), |
| 46 | + emptyArray: [], |
| 47 | + number: 0, |
| 48 | + arrayWithNullElements: [null, null], |
| 49 | + arrayWithEmptyString: [''], |
| 50 | + arrayWithStrings: ['string1', 'string2'], |
| 51 | + }; |
| 52 | + |
| 53 | + const actualObject = removeUndefinedElements(originalObject); |
| 54 | + |
| 55 | + expect(actualObject).toEqual(expectedObject); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should remove undefined elements from array', () => { |
| 59 | + const originalArray = [undefined, 'someString', 3, undefined, '', null, undefined, undefined]; |
| 60 | + const expectedArray = ['someString', 3, '', null]; |
| 61 | + |
| 62 | + const actualArray = removeUndefinedElements(originalArray); |
| 63 | + |
| 64 | + expect(actualArray).toEqual(expectedArray); |
| 65 | + }); |
| 66 | +}); |
0 commit comments