utils.test.ts 986 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { removeEmpty } from './utils';
  2. describe('removeEmpty', () => {
  3. it('Should remove all empty', () => {
  4. const original = {
  5. stringsShouldBeKept: 'Something',
  6. unlessTheyAreEmpty: '',
  7. nullToBeRemoved: null,
  8. undefinedToBeRemoved: null,
  9. zeroShouldBeKept: 0,
  10. booleansShouldBeKept: false,
  11. emptyObjectsShouldBeRemoved: {},
  12. emptyArrayShouldBeRemoved: [],
  13. nonEmptyArraysShouldBeKept: [1, 2, 3],
  14. nestedObjToBeRemoved: {
  15. toBeRemoved: undefined,
  16. },
  17. nestedObjectToKeep: {
  18. thisShouldBeRemoved: null,
  19. thisShouldBeKept: 'Hello, Grafana',
  20. },
  21. };
  22. const expectedResult = {
  23. stringsShouldBeKept: 'Something',
  24. zeroShouldBeKept: 0,
  25. booleansShouldBeKept: false,
  26. nonEmptyArraysShouldBeKept: [1, 2, 3],
  27. nestedObjectToKeep: {
  28. thisShouldBeKept: 'Hello, Grafana',
  29. },
  30. };
  31. expect(removeEmpty(original)).toStrictEqual(expectedResult);
  32. });
  33. });