-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix: drop getters and setters when diffing objects for error #9757
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2a33596
fix: do not override properties with setters when diffing objects
SimenB 4dcb197
link to PR
SimenB 395abcd
remove setters rather than ignoring properties that have them
SimenB 3503d77
only set writable if not getter and no setter
SimenB b14a485
add some frozen and not example with getters and setters
SimenB cf56846
use hasOwnProperty
SimenB 8f5824c
just create a new descriptor
SimenB 3aed077
simplify replaceable
SimenB 9ff198f
write tests that actually fail on master
SimenB 5f72f4e
remove faulty test and re-add enumerable check
SimenB 30495ca
move enumarable check
SimenB fe41787
add test for getter -> value change
SimenB 1aea89b
test enumerable skip
SimenB c0edc89
update changelog entry
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,28 +104,17 @@ describe('Replaceable', () => { | |
const replaceable = new Replaceable(object); | ||
const cb = jest.fn(); | ||
replaceable.forEach(cb); | ||
expect(cb.mock.calls.length).toBe(3); | ||
expect(cb).toHaveBeenCalledTimes(3); | ||
expect(cb.mock.calls[0]).toEqual([1, 'a', object]); | ||
expect(cb.mock.calls[1]).toEqual([2, 'b', object]); | ||
expect(cb.mock.calls[2]).toEqual([3, symbolKey, object]); | ||
}); | ||
|
||
test('object forEach do not iterate none enumerable symbol key', () => { | ||
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. check moved |
||
const symbolKey = Symbol('jest'); | ||
const object = {a: 1, b: 2}; | ||
Object.defineProperty(object, symbolKey, {enumerable: false}); | ||
const replaceable = new Replaceable(object); | ||
const cb = jest.fn(); | ||
replaceable.forEach(cb); | ||
expect(cb.mock.calls.length).toBe(2); | ||
expect(cb.mock.calls[0]).toEqual([1, 'a', object]); | ||
expect(cb.mock.calls[1]).toEqual([2, 'b', object]); | ||
}); | ||
|
||
test('array forEach', () => { | ||
const replaceable = new Replaceable([1, 2, 3]); | ||
const cb = jest.fn(); | ||
replaceable.forEach(cb); | ||
expect(cb).toHaveBeenCalledTimes(3); | ||
expect(cb.mock.calls[0]).toEqual([1, 0, [1, 2, 3]]); | ||
expect(cb.mock.calls[1]).toEqual([2, 1, [1, 2, 3]]); | ||
expect(cb.mock.calls[2]).toEqual([3, 2, [1, 2, 3]]); | ||
|
@@ -139,6 +128,7 @@ describe('Replaceable', () => { | |
const replaceable = new Replaceable(map); | ||
const cb = jest.fn(); | ||
replaceable.forEach(cb); | ||
expect(cb).toHaveBeenCalledTimes(2); | ||
expect(cb.mock.calls[0]).toEqual([1, 'a', map]); | ||
expect(cb.mock.calls[1]).toEqual([2, 'b', map]); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,18 +20,27 @@ test('returns the same value for primitive or function values', () => { | |
expect(deepCyclicCopyReplaceable(fn)).toBe(fn); | ||
}); | ||
|
||
test('does not execute getters/setters, but copies them', () => { | ||
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. So it's not just in the comments - we invoke the getters on purpose now, so this test doesn't make sense anymore |
||
const fn = jest.fn(); | ||
test('convert accessor descriptor into value descriptor', () => { | ||
const obj = { | ||
// @ts-ignore | ||
set foo(_) {}, | ||
get foo() { | ||
fn(); | ||
return 'bar'; | ||
}, | ||
}; | ||
expect(Object.getOwnPropertyDescriptor(obj, 'foo')).toEqual({ | ||
configurable: true, | ||
enumerable: true, | ||
get: expect.any(Function), | ||
set: expect.any(Function), | ||
}); | ||
const copy = deepCyclicCopyReplaceable(obj); | ||
|
||
expect(Object.getOwnPropertyDescriptor(copy, 'foo')).toBeDefined(); | ||
expect(fn).not.toBeCalled(); | ||
expect(Object.getOwnPropertyDescriptor(copy, 'foo')).toEqual({ | ||
configurable: true, | ||
enumerable: true, | ||
value: 'bar', | ||
writable: true, | ||
}); | ||
}); | ||
|
||
test('copies symbols', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
CI is failing on master due to this missing newline, snuck it in here