Repository navigation
Fix #1741: record calls on stubbed getters/setters - #2733
Conversation
|
This is a really clean fix. Thank you for picking it up, and for keeping it scoped — the diff is easy to follow and exactly addresses the issue. A couple of nice things I noticed 👏
One small suggestion: Nice work on this! |
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. Co-authored-by: Carl Erik Kopseng <carlerik@gmail.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a10d17-476c-73a6-8581-e0e0fa9a27f3 Co-authored-by: Carl Erik Kopseng <carlerik@gmail.com>
5f001bc to
3fc115e
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2733 +/- ##
=======================================
Coverage 97.45% 97.46%
=======================================
Files 39 39
Lines 1846 1852 +6
=======================================
+ Hits 1799 1805 +6
Misses 47 47
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I fixed the PR per Morgan's instructions. merging on checks turning green. |
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