[TLC-254] Tests for isObjectEmpty()

This commit is contained in:
Kim Shepherd
2022-05-03 14:11:02 +12:00
parent 833637c215
commit fd0c8f409e

View File

@@ -9,7 +9,7 @@ import {
isNotEmptyOperator,
isNotNull,
isNotUndefined,
isNull,
isNull, isObjectEmpty,
isUndefined
} from './empty.util';
@@ -444,6 +444,43 @@ describe('Empty Utils', () => {
});
});
describe('isObjectEmpty', () => {
/*
isObjectEmpty(); // true
isObjectEmpty(null); // true
isObjectEmpty(undefined); // true
isObjectEmpty(''); // true
isObjectEmpty([]); // true
isObjectEmpty({}); // true
isObjectEmpty({name: null}); // true
isObjectEmpty({ name: 'Adam Hawkins', surname : null}); // false
*/
it('should be empty if no parameter passed', () => {
expect(isObjectEmpty()).toBeTrue();
})
it('should be empty if null parameter passed', () => {
expect(isObjectEmpty(null)).toBeTrue();
})
it('should be empty if undefined parameter passed', () => {
expect(isObjectEmpty(undefined)).toBeTrue();
})
it('should be empty if empty string passed', () => {
expect(isObjectEmpty('')).toBeTrue();
})
it('should be empty if empty array passed', () => {
expect(isObjectEmpty([])).toBeTrue();
})
it('should be empty if empty object passed', () => {
expect(isObjectEmpty({})).toBeTrue();
})
it('should be empty if single key with null value passed', () => {
expect(isObjectEmpty({ name: null })).toBeTrue();
})
it('should NOT be empty if object with at least one non-null value passed', () => {
expect(isObjectEmpty({ name: 'Adam Hawkins', surname : null })).toBeFalse();
})
});
describe('ensureArrayHasValue', () => {
it('should let all arrays pass unchanged, and turn everything else in to empty arrays', () => {
const sourceData = {