sinonjs/sinon

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

Open

#1,741 opened on 2018年3月21日

GitHub で見る
 (27 comments) (0 reactions) (0 assignees)JavaScript (9,548 stars) (764 forks)batch import
Help wantedProperty accessorshacktoberfestpinned

説明

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

コントリビューターガイド

Cannot spy on property getters, and stubbed getters do not record calls · sinonjs/sinon#1741 | Good First Issue