कारतोफ्फेलस्क्रिप्ट™ 2023-04-28 09:49:53 +00:00 committed by GitHub
parent 5974af1903
commit 206b6b90b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -143,7 +143,8 @@ export function augmentObject<T extends object>(data: T): T {
},
getOwnPropertyDescriptor(target, key) {
return Object.getOwnPropertyDescriptor(data, key) ?? defaultPropertyDescriptor;
if (deletedProperties.indexOf(key) !== -1) return undefined;
return Object.getOwnPropertyDescriptor(key in newData ? newData : data, key);
},
});

View file

@ -528,5 +528,34 @@ describe('AugmentObject', () => {
const augmentedObject = augmentObject(originalObject);
expect(Object.keys(augmentedObject)).toEqual(['a', 'b']);
});
test('should return property descriptors', () => {
const originalObject = {
x: {
y: {},
z: {},
},
};
const augmentedObject = augmentObject(originalObject);
expect(Object.getOwnPropertyDescriptor(augmentedObject.x, 'y')).toEqual({
configurable: true,
enumerable: true,
value: {},
writable: true,
});
delete augmentedObject.x.y;
expect(augmentedObject.x.hasOwnProperty('y')).toEqual(false);
augmentedObject.x.y = 42;
expect(augmentedObject.x.hasOwnProperty('y')).toEqual(true);
expect(Object.getOwnPropertyDescriptor(augmentedObject.x, 'y')).toEqual({
configurable: true,
enumerable: true,
value: 42,
writable: true,
});
});
});
});