Stubbing a property getter, checking it was called

43 views
Skip to first unread message

Oli

unread,
Aug 28, 2017, 12:46:24 PM8/28/17
to Sinon.JS

I'm struggling to put the pieces together to stub a property value, and then check that it was retrieved.

For example:

var sinon = require('sinon');

var myObj = {
    prop: 'foo'
  };

var st = sinon.stub(myObj, 'prop').get(function getterFn() {
    return 'bar';
  });

console.log(myObj.prop);
console.log(st.called);

That doesn't work per https://github.com/sinonjs/sinon/issues/1545 - st.called remains false.

So if that's not the way to do it, what is?
Reply all
Reply to author
Forward
0 new messages