2023-08-10 15:13:24 +02:00
|
|
|
import { deepOmit } from './deepOmit';
|
|
|
|
|
|
|
|
test('should omit all instances of a given field', () => {
|
|
|
|
const input = {
|
|
|
|
name: 'some-name',
|
|
|
|
color: 'blue',
|
|
|
|
children: {
|
|
|
|
name: 'some-name',
|
|
|
|
color: 'blue',
|
|
|
|
children: {
|
|
|
|
name: 'some-name',
|
|
|
|
color: 'blue',
|
|
|
|
children: {
|
|
|
|
name: 'some-name',
|
|
|
|
color: 'blue',
|
|
|
|
children: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(deepOmit(input, 'name')).toEqual({
|
|
|
|
color: 'blue',
|
|
|
|
children: {
|
|
|
|
color: 'blue',
|
|
|
|
children: {
|
|
|
|
color: 'blue',
|
|
|
|
children: {
|
|
|
|
color: 'blue',
|
|
|
|
children: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(deepOmit(input, 'color')).toEqual({
|
|
|
|
name: 'some-name',
|
|
|
|
children: {
|
|
|
|
name: 'some-name',
|
|
|
|
children: {
|
|
|
|
name: 'some-name',
|
|
|
|
children: {
|
|
|
|
name: 'some-name',
|
|
|
|
children: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2024-05-14 12:42:39 +02:00
|
|
|
|
|
|
|
test('should omit all instances of multiple fields', () => {
|
|
|
|
const input = {
|
|
|
|
name: 'some-name',
|
|
|
|
color: 'blue',
|
|
|
|
children: {
|
|
|
|
name: 'some-name',
|
|
|
|
color: 'blue',
|
|
|
|
children: {
|
|
|
|
name: 'some-name',
|
|
|
|
color: 'blue',
|
|
|
|
children: {
|
|
|
|
name: 'some-name',
|
|
|
|
color: 'blue',
|
|
|
|
children: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(deepOmit(input, 'name', 'color')).toEqual({
|
|
|
|
children: {
|
|
|
|
children: {
|
|
|
|
children: {
|
|
|
|
children: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|