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
1212Let'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
2322To 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
2827const mockCallback = jest .fn (x => 42 + x);
2928
You can’t perform that action at this time.
0 commit comments