You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replaces getter for `property` on `object` with `replacement` argument. Attempts to replace an already replaced getter cause an exception.
241
+
Usually one intends to _replace_ the value or getter of a field, but there are use cases where one actually wants to _assign_ a value to a property using an existing setter. `#replace.usingAccessor(object, property, value)` will do just that; pass the value into setter function and vice-versa use the getter to get the value used for restoring later on.
242
+
243
+
##### Use case: no-frills dependency injection in ESM with cleanup
244
+
245
+
One use case can be to conveniently allow ESM module stubbing using pure dependency injection, having Sinon help you with the cleanup, without resorting to external machinery such as module loaders or require hooks (see [#2403](https://github.com/sinonjs/sinon/issues/2403)). This would then work regardless of bundler, browser or server environment.
Replaces an existing getter for `property` on `object` with the `replacementFunction` argument. Attempts to replace an already replaced getter cause an exception.
242
250
243
251
`replacement` must be a `Function`, and can be instances of `spies`, `stubs` and `fakes`.
Replaces setter for `property` on `object` with `replacement` argument. Attempts to replace an already replaced setter cause an exception.
270
+
Replaces an existing setter for `property` on `object` with the `replacementFunction` argument. Attempts to replace an already replaced setter cause an exception.
263
271
264
272
`replacement` must be a `Function`, and can be instances of `spies`, `stubs` and `fakes`.
0 commit comments