Repository navigation
Add mock.property to node:test - #8383
Merged
Merged
Conversation
Node v24.3.0 added mock.property(object, propertyName[, value]) to the node:test MockTracker, but workerd's port only has fn, method, getter and setter. Code that spies on plain data properties fails with "mock.property is not a function". In this patch we: - port MockPropertyContext and MockTracker.property from Node, with accesses, accessCount, mockImplementation, mockImplementationOnce, resetAccesses and restore - store each tracked mock with its own restore function, as Node does, so reset() and restoreAll() restore property mocks too - port Node's mock.property tests from test-runner-mocking.js This adds a method to an existing object that is only reachable through node:test, which requires nodejs_compat. It ships without a compatibility flag: new node: exports have been accepted without one, and a Worker that does not call mock.property sees no change.
There was a problem hiding this comment.
✅ Approved — A faithful port of Node's mock.property with matching tests; no correctness, security, performance or documentation issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns. This is test-runner instrumentation that can only be reached through node:test.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found. The per-mock restore function is wired up the same way for function mocks and property mocks.
⚡ Performance: ✅ LGTM
No performance issues. Recording an access record and stack for each property access is opt-in test instrumentation, and resetAccesses() clears it.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: d22988e7
ryanking13
approved these changes
Nov 12, 2026
jasnell
approved these changes
Nov 12, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Node v24.3.0 added
mock.property(object, propertyName[, value])to thenode:testMockTracker, but workerd's port only hasfn,method,getterandsetter, so code that mocks a plain data property fails withmock.property is not a function.In this patch:
MockPropertyContextandMockTracker.propertyare ported from Node'slib/internal/test_runner/mock/mock.js, withaccesses,accessCount(),mockImplementation(),mockImplementationOnce(),resetAccesses()andrestore().reset()andrestoreAll()restore property mocks too.mock.propertytests fromtest-runner-mocking.jsare ported. The one that relies on per-testt.mockauto-restore is replaced with arestoreAll()/reset()check, since workerd'snode:testhas no per-test context.mock.property(obj, 'foo', 42)TypeError: mock.property is not a functionobj.foo === 42prop.mock.accessCount()1after one readmock.restoreAll()obj.fooback to its original valueThis adds a method that is only reachable through
node:testundernodejs_compat, so it ships without a compatibility flag.