omit.spec.ts 788 B

12345678910111213141516171819202122232425262728293031
  1. import { omit } from './omit';
  2. describe('omit()', () => {
  3. it('returns a new object', () => {
  4. const obj = { foo: 1, bar: 2 };
  5. expect(omit(obj, ['bar'])).not.toBe(obj);
  6. });
  7. it('works with 1-level-deep objects', () => {
  8. expect(omit({ foo: 1, bar: 2 }, ['bar'])).toEqual({ foo: 1 });
  9. expect(omit({ foo: 1, bar: 2 }, ['bar', 'foo'])).toEqual({});
  10. });
  11. it('works with deeply-nested objects', () => {
  12. expect(omit({
  13. name: {
  14. first: 'joe',
  15. last: 'smith',
  16. },
  17. address: {
  18. number: 12,
  19. },
  20. }, ['address'])).toEqual({
  21. name: {
  22. first: 'joe',
  23. last: 'smith',
  24. },
  25. });
  26. });
  27. });