@cnamts/vue-dot
Version:
Implementation of our Design System for the French Health Insurance
72 lines (55 loc) • 1.11 kB
text/typescript
import { deepRemoveKeys } from '../';
import { deepCopy } from '../../deepCopy';
const BASE_OBJECT = {
b: 'b',
c: [
{
e: 'e'
}
]
};
const DEEP_OBJECT = {
a: BASE_OBJECT
};
const DEEP_ARRAY = [
BASE_OBJECT
];
describe('deepRemoveKeys', () => {
it('deletes a key', () => {
const deepObject = deepCopy(DEEP_OBJECT);
const newCollection = deepRemoveKeys(deepObject, 'c');
expect(newCollection).toEqual({
a: {
b: 'b'
}
});
});
it('deletes multiple keys', () => {
const deepObject = deepCopy(DEEP_OBJECT);
const newCollection = deepRemoveKeys(deepObject, ['b', 'c']);
expect(newCollection).toEqual({
a: {}
});
});
it('deletes deep key in object', () => {
const deepObject = deepCopy(DEEP_OBJECT);
const newCollection = deepRemoveKeys(deepObject, 'e');
expect(newCollection).toEqual({
a: {
b: 'b',
c: [
{}
]
}
});
});
it('deletes deep key in array', () => {
const deepArray = deepCopy(DEEP_ARRAY);
const newCollection = deepRemoveKeys(deepArray, 'c');
expect(newCollection).toEqual([
{
b: 'b'
}
]);
});
});