File tree Expand file tree Collapse file tree 1 file changed +2
-3
lines changed Expand file tree Collapse file tree 1 file changed +2
-3
lines changed Original file line number Diff line number Diff line change @@ -12,18 +12,17 @@ There are two ways to mock functions: Either by creating a mock function to use
12
12
Let's imagine we're testing an implementation of a function ` forEach ` , which invokes a callback for each item in a supplied array.
13
13
14
14
``` js title="forEach.js"
15
- function forEach (items , callback ) {
15
+ export function forEach (items , callback ) {
16
16
for (const item of items) {
17
17
callback (item);
18
18
}
19
19
}
20
- module .exports = forEach;
21
20
```
22
21
23
22
To test this function, we can use a mock function, and inspect the mock's state to ensure the callback is invoked as expected.
24
23
25
24
``` js title="forEach.test.js"
26
- const forEach = require ( ' ./forEach' ) ;
25
+ import { forEach } from ' ./forEach' ;
27
26
28
27
const mockCallback = jest .fn (x => 42 + x);
29
28
You can’t perform that action at this time.
0 commit comments