Skip to content

Commit 48b204c

Browse files
authored
Update MockFunctions.md
1 parent e416d58 commit 48b204c

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

docs/MockFunctions.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ There are two ways to mock functions: Either by creating a mock function to use
1212
Let's imagine we're testing an implementation of a function `forEach`, which invokes a callback for each item in a supplied array.
1313

1414
```js title="forEach.js"
15-
function forEach(items, callback) {
15+
export function forEach(items, callback) {
1616
for (const item of items) {
1717
callback(item);
1818
}
1919
}
20-
module.exports = forEach;
2120
```
2221

2322
To test this function, we can use a mock function, and inspect the mock's state to ensure the callback is invoked as expected.
2423

2524
```js title="forEach.test.js"
26-
const forEach = require('./forEach');
25+
import { forEach } from './forEach';
2726

2827
const mockCallback = jest.fn(x => 42 + x);
2928

0 commit comments

Comments
 (0)