-
-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,13 +181,13 @@ A convenience reference for [`sinon.assert`](./assertions) | |
|
||
_Since `[email protected]`_ | ||
|
||
#### `sandbox.replace(object, property, replacement);` | ||
#### `sandbox.replace(object, property, replacement, options);` | ||
|
||
Replaces `property` on `object` with `replacement` argument. Attempts to replace an already replaced value cause an exception. Returns the `replacement`. | ||
|
||
`replacement` can be any value, including `spies`, `stubs` and `fakes`. | ||
|
||
This method only works on non-accessor properties, for replacing accessors, use `sandbox.replaceGetter()` and `sandbox.replaceSetter()`. | ||
By default, this method only works on non-accessor properties, for replacing accessors, use `sandbox.replaceGetter()` and `sandbox.replaceSetter()`. | ||
|
||
```js | ||
var myObject = { | ||
|
@@ -204,6 +204,8 @@ console.log(myObject.myMethod()); | |
// strawberry | ||
``` | ||
|
||
You _can_ pass the option `{forceAssignment: boolean}` to avoid throwing on encountering a setter. This will pass the replacement into setter function and vice-versa use the getter to get the value used for restoring later on. One use case can be to do ESM module stubbing without resorting to external machinery such as module loaders (see [#2403](https://github.com/sinonjs/sinon/issues/2403)). | ||
|
||
#### `sandbox.replaceGetter();` | ||
|
||
Replaces getter for `property` on `object` with `replacement` argument. Attempts to replace an already replaced getter cause an exception. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters