sinonjs / sinonjs/sinon

Cannot spy on property getters, and stubbed getters do not record calls

Open
#1,741 27 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

hacktoberfest Help wanted pinned Property accessors
Dominant language
JavaScript
Stars
9.8k
Forks
809
PR merge metrics
No merged PRs in 30d

Description

  • Sinon version : 4.4.6
  • Environment : Chrome 65.0.3325.162 on Mac
  • Example URL : N/A
  • Other libraries you are using: N/A

What did you expect to happen?

I'm attempting to stub out - and monitor - a property getter,
using the stubbing approach recommended in the documentation at http://sinonjs.org/releases/v4.4.6/stubs/#stubgetgetterfn

I was hoping that the resulting stub would report when the getter was actually invoked, but no such reports are logged.

(In fact, I don't actually want to stub the getter: I merely want to spy on it, but Sinon provides no property getter spy API right now afaik.)

What actually happens

I can successfully stub out the getter, and control what it does, but Sinon's invocation recording reports no calls.

(This is also related to issue #1545.)

I do understand that, for a stubbed property, there are really two sets of function calls going on - the getter and the setter - and so really there should be two sets of recordings going on. But right now, there are none: when stubbing a property, as recommended in the docs above, no recording happens.

How to reproduce

There's a small example at https://codesandbox.io/s/l5m9loy21l; output is in the console.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the getter-stubbing approach linked in the Sinon 4.4.6 documentation and reproduce the behavior using the CodeSandbox example. Review issue #1545 and the 27-comment discussion for existing decisions. Done means property getter invocations are recorded, with the requested getter-spying behavior clarified and covered by the project's tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.