November 2017
Beginner to intermediate
398 pages
8h 42m
English
To support JavaScript import/export modules and dynamic imports inside Jest, we will need to change our babel configuration when the tests are run.
We need to add two babel plugins to the configuration, when the NODE_ENV environment variable is set to "test":
{ "presets": [ ["env", { "modules": false }], "stage-3" ], "env": { "test": { "plugins": [ "transform-es2015-modules-commonjs", "dynamic-import-node" ] } }}
The transform-es2015-modules-commonjs plugin adds support for import/export syntax to Jest, and the dynamic-import-node adds support for dynamic imports.
Read now
Unlock full access