Fix #1741: record calls on stubbed getters/setters#2733
Open
youdie006 wants to merge 1 commit into
Open
Conversation
stub.get(fn)/stub.set(fn) installed the raw replacement function as the property accessor, so invoking the stubbed getter/setter ran untracked and never incremented callCount. Wrap the replacement in a spy and expose it as stub.getter/stub.setter so accessor invocations are recorded, mirroring the spy.get/spy.set surface. Scoped and non-breaking.
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.
Purpose (TL;DR)
stub.get(fn)/stub.set(fn)installed the raw replacement function directly as the property accessor, so invoking a stubbed getter/setter ran untracked —callCountnever incremented (#1741). This wraps the replacement in a spy and exposes it asstub.getter/stub.setter, so accessor invocations are recorded (mirroring the existingspy.get/spy.setsurface). This is the scoped "tiny PR" @fatso83 green-lit in the issue thread.How to verify
npx mocha test/src/stub-test.js --grep "records calls to the stubbed"→ 2 passing.Checklist
eslint --max-warnings 0; prettier clean)default-behaviors.js, no API removed); full suite 1554 passing / 0 failing locally.Fixes #1741