如果使用--no-cache
运行Jest,则此测试通过,但根据下面的错误消息,我不应该使用babel-jest
获取错误。
请参阅下面的.babelrc和package.json以及测试文件。
错误:
Using Jest CLI v12.1.1, jasmine2, babel-jest
FAIL __tests__/junk-test.js
Runtime Error
- SyntaxError: Unexpected reserved word in file 'junk.js'.
Make sure your preprocessor is set up correctly and ensure your 'preprocessorIgnorePatterns' configuration is correct: http://facebook.github.io/jest/docs/api.html#preprocessorignorepatterns-array-string
If you are currently setting up Jest or modifying your preprocessor, try `jest --no-cache`.
Preprocessor: node_modules/babel-jest/src/index.js.
Make sure your '.babelrc' is set up correctly, for example it should include the 'es2015' preset.
Jest tried to the execute the following preprocessed code:
var junk = function () {
return "thing";};
export { junk };
__测试__ /垃圾test.js
// __tests__/junk-test.js
jest.unmock('../junk.js');
import {junk} from '../junk';
describe('JUNK AwesomeProject', () => {
it('Junk var = string', () => {
var retVal = junk();
expect(retVal).toEqual("thing");
});
});
junk.js
var junk = function(){
return "thing";
}
export {junk};
的package.json
{
"dependencies": {
"babel-preset-react": "6.5.0",
"babelify": "7.3.0",
"react": "15.1.0",
"react-dom": "15.1.0"
},
"devDependencies": {
"babel-jest": "12.1.0",
"babel-polyfill": "6.9.0",
"babel-preset-es2015": "*",
"jest-cli": "12.1.1",
"react-addons-test-utils": "15.1.0"
},
"scripts": {
"test": "jest"
},
"jest": {
"verbose": true,
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react/",
"<rootDir>/node_modules/react-dom/",
"<rootDir>/node_modules/react-addons-test-utils/"
]
}
}
.babelrc
{
"presets": ["es2015", "react"]
}
稀释。将junk.js更改为显式返回,现在测试通过。
奇怪的是Flow并没有抓住这个,也许ESlint会在我的名单上下一个尝试:
var junk = function() {
var stuff = "thing";
return stuff;
}