withProxy() function
Creates a Proxy around a value
, and calls the callback
with it.
Signature:
declare function withProxy<T, R = unknown>(value: T, callback: (proxy: Proxy<T>) => R): R;
Parameters
Parameter | Type | Description |
---|---|---|
value | T | The value to wrap a Proxy around. |
callback | (proxy: Proxy<T>) => R | A function to invoke with the created proxy. |
Returns:
R
Whatever the callback
returns is propagated back out.
Example
withProxy(person, (proxy) => {
expect(proxy.parent.cars).to.be.empty();
});
Error message:
Expected parent.cars to be empty, but it had 2 elements.