sinonjs/sinon

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

Open

#1741 aperta il 21 mar 2018

Vedi su GitHub
 (27 commenti) (0 reazioni) (0 assegnatari)JavaScript (764 fork)batch import
Help wantedProperty accessorshacktoberfestpinned

Metriche repository

Star
 (9548 star)
Metriche merge PR
 (Merge medio 6g 16h) (15 PR mergiate in 30 g)

Descrizione

  • 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.

Guida contributor