Skip to content

Commit ad58467

Browse files
committed
Add docs for the new API get and set behaviors
1 parent eb7f90f commit ad58467

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

docs/release-source/release/stubs.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,38 @@ var stub = sinon.stub().returnsNum(42);
448448

449449
assert.equals(stub(), 42);
450450
```
451+
452+
#### `stub.get(getterFn)`
453+
454+
Replaces a new getter for this stub.
455+
456+
```javascript
457+
var myObj = {
458+
prop: 'foo'
459+
};
460+
461+
createStub(myObj, 'prop').get(function getterFn() {
462+
return 'bar';
463+
});
464+
465+
myObj.example; // 'bar'
466+
```
467+
468+
#### `stub.set(setterFn)`
469+
470+
Defines a new setter for this stub.
471+
472+
```javascript
473+
var myObj = {
474+
example: 'oldValue',
475+
prop: 'foo'
476+
};
477+
478+
createStub(myObj, 'prop').set(function setterFn(val) {
479+
myObj.example = val;
480+
});
481+
482+
myObj.prop = 'baz';
483+
484+
myObj.example; // 'baz'
485+
```

0 commit comments

Comments
 (0)