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
-[Mock HTML5 Canvas in JSDOM](#mock-html5-canvas-in-jsdom)
32
+
-[Mock a dependency using Jest](#mock-a-dependency-using-jest)
30
33
-[Mock an entire library](#mock-an-entire-library)
31
34
-[Mock complex objects](#mock-complex-objects)
32
35
-[Browser/Node Support](#browsernode-support)
33
36
-[Performance & Size](#performance--size)
34
37
35
38
## About
36
39
37
-
Have you ever wanted to mock something that has lots of nested properties and functions? You don't need all of those to be implemented. You just want them to exist so the code doesn't crash. This is the solution.
40
+
This is an easy-to-use library which enables you to instantly mock anything. Any properties, functions, classes, etc will be instantly mocked with one line. Useful when you need to provide a mock, but don't care about the implementation. With this library you can then do many other advanced things such as: overriding certain operations, inspect what operations occurred, replay all operations onto another object, and more!
38
41
39
42
Recursive Proxy Mock is a [JavaScript Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) that can handle literally anything. This is best explained with examples. Read on!
@@ -253,6 +256,12 @@ A `ProxyData` object contains any relevant details about the operation. For exam
253
256
- All other handlers:
254
257
- No useful additional information is available
255
258
259
+
### `resetMock(proxy)`
260
+
261
+
Resets the internally tracked proxy operations. See the [Mock a dependency using Jest](#mock-a-dependency-using-jest) example for a common usage of this method.
262
+
263
+
-`proxy` - the root proxy object that was returned from `recursiveProxyMock`
264
+
256
265
### `replayProxy(proxy, target)`
257
266
258
267
Replay every operation performed on a proxy mock object onto a target object. This can effectively let you time travel to queue up any actions and replay them as many times as you would like. Every property accessor, every function call, etc will be replayed onto the target.
@@ -269,6 +278,13 @@ This is exposed primarily for debugging or curiosity and shouldn't be relied on.
269
278
-`proxy` - the root proxy object that was returned from `recursiveProxyMock`
270
279
- Returns: Array of [ProxyData](#proxydata) objects for every operation that was performed on the mock.
271
280
281
+
### `listAllProxyPaths(proxy) => ProxyPath[]`
282
+
283
+
A debug function which lists every path and sub-path that was visited on the mock. This is an array of [ProxyPath](#proxypath) arrays which is useful to manually inspect what operations took place and find the correct paths to use for the other APIs.
284
+
285
+
-`proxy` - the root proxy object that was returned from `recursiveProxyMock`
286
+
- Returns: Array of [ProxyPath](#proxypath) arrays with one entry for every path or sub-path that was visited.
287
+
272
288
### ProxyPath
273
289
274
290
Whenever a method accepts a `path` it is an array of properties and symbols to define a request path on the mock object. (See [ProxySymbol](#proxysymbol) for more details.)
@@ -291,13 +307,34 @@ Whenever a method accepts a `path` it is an array of properties and symbols to d
291
307
JSDOM doesn't implement the Canvas element so if you are testing code that is drawing on a canvas, it'll crash as soon as it tries to interact with the canvas context. You can use `recursiveProxyMock` to mock every method/property on the context for both 2d and WebGL. None of them will do anything, but the code will no longer crash and you can assert that the required functions were called.
0 commit comments