Exports defaults else path not taken with Jest and ES6

元气小坏坏 提交于 2021-02-07 19:22:22

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/40660511/exports-defaults-else-path-not-taken-with-jest-and-es6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!