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
{{ message }}
This repository was archived by the owner on Apr 18, 2022. It is now read-only.
@@ -57,14 +57,14 @@ Node.js fully supports ES Modules.
57
57
If a Node.js package has the type "module" specified in its package.json file, the JavaScript bundle can be imported as a `.js` file.
58
58
59
59
```js
60
-
import { spy, Spy } from"./mock_v0.4.0.js";
60
+
import { spy, Spy } from"./mock_v0.5.0.js";
61
61
```
62
62
63
63
The default type for Node.js packages is "commonjs".
64
64
To import the bundle into a commonjs package, the file extension of the JavaScript bundle must be changed from `.js` to `.mjs`.
65
65
66
66
```js
67
-
import { spy, Spy } from"./mock_v0.4.0.mjs";
67
+
import { spy, Spy } from"./mock_v0.5.0.mjs";
68
68
```
69
69
70
70
See [Node.js Documentation](https://nodejs.org/api/esm.html) for more information.
@@ -82,15 +82,15 @@ Script tags for ES modules must have the type attribute set to "module".
82
82
83
83
```js
84
84
// main.js
85
-
import { spy, Spy } from"./mock_v0.4.0.js";
85
+
import { spy, Spy } from"./mock_v0.5.0.js";
86
86
```
87
87
88
88
You can also embed a module script directly into an HTML file by placing the JavaScript code
89
89
within the body of the script tag.
90
90
91
91
```html
92
92
<scripttype="module">
93
-
import { spy, Spy } from"./mock_v0.4.0.js";
93
+
import { spy, Spy } from"./mock_v0.5.0.js";
94
94
</script>
95
95
```
96
96
@@ -100,7 +100,7 @@ See [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/
100
100
101
101
Below are some examples of how to use Spys, Stubs, and FakeTime in tests. When spying/stubing instance methods, you should wrap the calls and expectations with a try block then restore the function in a finally block to ensure the original instance method is restored before continuing to other tests. The same applies when using fake time.
102
102
103
-
See [deno docs](https://doc.deno.land/https/deno.land/x/mock@v0.4.0/mod.ts) for more information.
103
+
See [deno docs](https://doc.deno.land/https/deno.land/x/mock@v0.5.0/mod.ts) for more information.
104
104
105
105
### Spy
106
106
@@ -109,8 +109,8 @@ When spying on a function or instance method, all arguments and return values ar
109
109
If you have a function that takes a callback but you don't need it to do anything, you can create an empty spy. An empty spy will just return undefined for any calls made to it.
function filter<T>(values:T[], callback: (value:T) =>boolean):any[] {
144
144
returnvalues.filter(callback);
@@ -165,8 +165,8 @@ Deno.test("calls real callback", () => {
165
165
If you have an instance method that needs to still behave normally, you can wrap it with a spy. When you are done spying on a method, you need to call the restore function on the spy object to remove the wrapper from the instance method. If it is not restored and you attempt to wrap it again, it will throw a spy error saying "already spying on function".
@@ -249,8 +249,8 @@ When stubbing an instance method, all arguments and return values are recorded b
249
249
If you have an instance method but you don't need it to do or return anything, you can create an empty stub. An empty stub will just return undefined for any calls made to it. If you need it to return specific values instead, you can add return values after initialization by replacing or adding to the `stub.returns` queue. When the returns queue is empty, it will return undefined.
If you have an instance method but need it to return specific values for each call, you can create a stub with an array of values in the order that you want them returned. You can add more return values after initialization by replacing or adding to the `stub.returns` queue.
If you have an instance method but need it to call a replacement function instead of the original, you can create a stub with a replacement function. If you need it to return specific values instead, you can add return values after initialization by replacing or adding to the `stub.returns` queue. When the returns queue is empty, it will call the replacement function.
0 commit comments