-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
test_runner: support object property mocking #58438
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
Conversation
Review requested:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58438 +/- ##
==========================================
+ Coverage 90.20% 90.22% +0.01%
==========================================
Files 635 635
Lines 187174 187774 +600
Branches 36751 36866 +115
==========================================
+ Hits 168846 169421 +575
- Misses 11120 11126 +6
- Partials 7208 7227 +19
🚀 New features to boost your workflow:
|
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.
Thanks for working on this. I think this is a good start, but I'd like to see it more unified with the rest of the mocking framework (particularly mock.method()
since the use case is so similar)
Thanks for the thorough review! 😃 |
…provided and rename property mock tests to align with the ones in `test-runner-mocking.js`.
Hey, welcome @idango10 nice seeing you around here, I trust Colin and agree with his feedback. |
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.
This is looking pretty good to me. Two notes:
- It doesn't appear that a
mockImplementationOnce()
equivalent is implemented. - Can we add a test for explicitly mocking a property as
undefined
. This will definitely come up eventually, and I don't think the current implementation can support it. It might take a little bit of work to distinguish between the "explicitundefined
" and "use the previously existing value" use cases.
…d not passing value parameter at all and add test for undefined mock property value
|
Personally, I would just let it apply to both sets and gets and document the caveat you mentioned here. We could make it only apply to gets, but that would be inconsistent with how the rest of the implementation works and we would still need to document that caveat. |
…r single invocation behavior
I added |
doc/api/test.md
Outdated
* `object` {Object} The object whose value is being mocked. | ||
* `propertyName` {string|symbol} The identifier of the property on `object` to mock. | ||
* `value` {any} An optional value used as the mock value | ||
for `object[valueName]`. **Default:** The original property value. |
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.
for `object[valueName]`. **Default:** The original property value. | |
for `object[propertyName]`. **Default:** The original property value. |
valueName -> propertyName
Hey @cjihrig, hope you're doing well! Sorry to ping you, but I wanted to check if you've had a chance to look at my latest changes. Please let me know if anything needs tweaking. Thanks a lot! |
it seems like the API just takes a value - what about getters/setters, enumerability, writability? |
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
Mocking a value for testing why would modification of property descriptors be desirable? |
Landed in 905a722 |
@peteduel because enumerability and writability are all things that should be tested? |
PR-URL: nodejs#58438 Fixes: nodejs#58322 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Fixes: #58322
This PR adds object property mocking to the test runner.
Example usage: