Skip to content

Commit

Permalink
docs(JestObjectAPI jest-mock): Add example for ES6 modules
Browse files Browse the repository at this point in the history
Issue #8543
  • Loading branch information
sargalias committed Jun 10, 2019
1 parent 9ac8ca7 commit f076766
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/JestObjectAPI.md
Expand Up @@ -240,6 +240,23 @@ const moduleName = require('../moduleName');
moduleName(); // Will return '42';
```

When using the `factory` parameter for an ES6 module with a default export, the `__esModule: true` property needs to be specified:

```js
import moduleName, {foo} from '../moduleName';

jest.mock('../moduleName', () => {
return {
__esModule: true,
default: jest.fn(() => 42),
foo: jest.fn(() => 43),
};
});

moduleName(); // Will return 42
foo(); // Will return 43
```

The third argument can be used to create virtual mocks – mocks of modules that don't exist anywhere in the system:

```js
Expand Down

0 comments on commit f076766

Please sign in to comment.