object.test.ts 601 B

12345678910111213141516171819202122232425262728
  1. import { sortedDeepCloneWithoutNulls } from './object';
  2. describe('objects', () => {
  3. const value = {
  4. hello: null,
  5. world: {
  6. deeper: 10,
  7. foo: null,
  8. arr: [null, 1, 'hello'],
  9. },
  10. bar: undefined,
  11. simple: 'A',
  12. };
  13. it('returns a clean copy', () => {
  14. const copy = sortedDeepCloneWithoutNulls(value);
  15. expect(copy).toMatchObject({
  16. world: {
  17. deeper: 10,
  18. arr: [null, 1, 'hello'],
  19. },
  20. simple: 'A',
  21. });
  22. expect(value.hello).toBeNull();
  23. expect(value.world.foo).toBeNull();
  24. expect(value.bar).toBeUndefined();
  25. });
  26. });