问题
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