-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
handle Symbol properties and non-enumerable properties in replaceEqualDeep
#4237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,44 @@ describe('replaceEqualDeep', () => { | |
expect(result).toStrictEqual(obj2) | ||
}) | ||
|
||
describe('symbol properties', () => { | ||
it('should look at symbol properties in the object comparison', () => { | ||
const propertyKey = Symbol('property') | ||
const obj1 = { a: 1, [propertyKey]: 2 } | ||
const obj2 = { a: 1, [propertyKey]: 3 } | ||
const result = replaceEqualDeep(obj1, obj2) | ||
expect(result).toStrictEqual(obj2) | ||
}) | ||
|
||
it('should copy over symbol properties when creating a new object', () => { | ||
const propertyKey = Symbol('property') | ||
const obj1 = { a: 1, [propertyKey]: 2 } | ||
const obj2 = { a: 3, [propertyKey]: 2 } | ||
const result = replaceEqualDeep(obj1, obj2) | ||
expect(result).toStrictEqual(obj2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without this PR:
|
||
}) | ||
}) | ||
|
||
describe('non-enumerable properties', () => { | ||
it('should treat objects with non-enumerable properties as non-plain (no need for property comparisons)', () => { | ||
const obj1: { a: number; b?: number } = { a: 1 } | ||
Object.defineProperty(obj1, 'b', { enumerable: false, value: 2 }) | ||
const obj2: { a: number; b?: number } = { a: 1 } | ||
Object.defineProperty(obj2, 'b', { enumerable: false, value: 3 }) | ||
const result = replaceEqualDeep(obj1, obj2) | ||
expect(result).toBe(obj2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without this PR:
|
||
}) | ||
|
||
it("should treat objects with non-enumerable properties as non-plain (copying doesn't happen)", () => { | ||
const obj1: { a: number; b?: number } = { a: 1 } | ||
Object.defineProperty(obj1, 'b', { enumerable: false, value: 2 }) | ||
const obj2: { a: number; b?: number } = { a: 3 } | ||
Object.defineProperty(obj2, 'b', { enumerable: false, value: 2 }) | ||
const result = replaceEqualDeep(obj1, obj2) | ||
expect(result).toBe(obj2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without this PR:
|
||
}) | ||
}) | ||
|
||
it('should properly handle non-existent keys', () => { | ||
const obj1 = { a: 2, c: 123 } | ||
const obj2 = { a: 2, c: 123, b: undefined } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without this PR: