cjohansen/Sinon.JS — Issue #88: Wrap ES5 getters and setters
Author: rvagg
Created: 2012-03-03 10:27:09+00:00
State: open

```js
var o = {
get foobar() { return 'foobar' },
set foobar(s) { throw 'bzzt!' },
foo: function() { return 'foo' },
bar: 'bar'
}; // -> { foobar: [Getter/Setter], foo: [Function], bar: 'bar' }

sinon.mock(o).expects('foobar').returns('woohoo'); // doesn't because sinon.wrapMethod() does an object[property] which accesses the getter which returns a string
```

To support getters and setters you need to do a `Object.getOwnPropertyDescriptor(obj, prop)` for the object and then a recursive `Object.getPrototypeOf(obj)` if it doesn't exist, the descriptor has a `'get'` and `'set'` property where they are defined.

But, you may want to mock out just the getter or just the setter or both, so how do you specify that? Some options:

```js
mock(o).expects('foobar'); // ambiguous, the setter? getter? or both?
mock(o).expects('get foobar'); // ambiguous, there may be a legitimate property named "get foobar"
mock(o).expectsGet('foobar'); // clear but more code in Sinon and more to document ?
mock(o).expectsSet('foobar'); // ditto
```

And also, do you have a convention in place already for dealing with features that may not be present in the current environment? If someone tries to do this in IE6 what should happen?