Albert Olivé Albert Olivé - 3 years ago 178
React JSX Question

Exports defaults else path not taken with Jest and ES6

I'm having issues to pass my tests with 100% coverage. Istanbul say that

exports defaults Component
else path not taken.

Because of that, I see in my generated html of istanbul that my tests are not completely at 100%. Mostly in the Statements and Branches tab.

I'm using:


  • React: 15.4.0

  • Jest: 17.0.2

  • Webpack: 1.12.11



Any idea?

enter image description here
enter image description here

Answer Source

The problem was in the jest configuration, we were using a preprocessor in order to resolve some imports:

In the package json we had this:

"transform": {
  "^.+\\.js$": "<rootDir>/cfg/preprocessor.js"
},

This file contained this:

const babelJest = require('babel-jest');
require('babel-register');
const webpackAlias = require('jest-webpack-alias');

module.exports = {
  process: function (src, filename) {
    if (filename.indexOf('node_modules') === -1) {
      src = babelJest.process(src, filename);
      src = webpackAlias.process(src, filename);
    }
    return src;
  }
};

We updated to Jest v20 and also use the module resolver from Jest, in our package.json we added:

"moduleDirectories": [
  "node_modules",
  "src"
],

and removed the transform config from the package.json and the preprocessor.js file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download