-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
implement spyOnProperty method #5107
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 1 commit
1a3b82a
4cfb737
65d884d
a4a6313
d26337c
7c4844d
afb0e96
05a303d
fc0de22
0a5e083
c0894d9
be83146
e5aa9a6
26b5ddb
95f0ab9
bd44ca5
37093f6
224eb25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,7 +131,9 @@ export default function SpyRegistry(options: Object) { | |
|
|
||
| this.spyOnProperty = function(obj, propertyName, accessType = 'get') { | ||
| if (!obj) { | ||
| throw new Error('spyOn could not find an object to spy upon for ' + propertyName + ''); | ||
| throw new Error( | ||
| 'spyOn could not find an object to spy upon for ' + propertyName + '', | ||
|
||
| ); | ||
| } | ||
|
|
||
| if (!propertyName) { | ||
|
|
@@ -154,7 +156,9 @@ export default function SpyRegistry(options: Object) { | |
| } | ||
|
|
||
| if (!descriptor[accessType]) { | ||
| throw new Error('Property ' + propertyName + ' does not have access type ' + accessType); | ||
| throw new Error( | ||
| 'Property ' + propertyName + ' does not have access type ' + accessType, | ||
| ); | ||
| } | ||
|
|
||
| if (obj[propertyName] && isSpy(obj[propertyName])) { | ||
|
|
@@ -172,20 +176,22 @@ export default function SpyRegistry(options: Object) { | |
| let restoreStrategy; | ||
|
|
||
| if (Object.prototype.hasOwnProperty.call(obj, propertyName)) { | ||
| restoreStrategy = function () { | ||
| restoreStrategy = function() { | ||
| Object.defineProperty(obj, propertyName, originalDescriptor); | ||
| }; | ||
| } else { | ||
| restoreStrategy = function () { | ||
| restoreStrategy = function() { | ||
| delete obj[propertyName]; | ||
| }; | ||
| } | ||
|
|
||
| currentSpies().push({ | ||
| restoreObjectToOriginalState: restoreStrategy | ||
| restoreObjectToOriginalState: restoreStrategy, | ||
| }); | ||
|
|
||
| const spiedDescriptor = Object.assign({}, descriptor, { [accessType]: spiedProperty }) | ||
| const spiedDescriptor = Object.assign({}, descriptor, { | ||
| [accessType]: spiedProperty, | ||
| }); | ||
|
|
||
| Object.defineProperty(obj, propertyName, spiedDescriptor); | ||
|
|
||
|
|
||
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.
why was this changed? This seems unrelated.
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.
i got runtime errors when developing this feature when
uncheckedCountis falsy. do you think that this change is not required?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.
I think this should be changed in a separate commit, with a test that is fixed by your change. Please revert it from this PR and send one for this issues specifically. Thank you.