【发布时间】:2018-02-08 14:27:07
【问题描述】:
我在切换到笔记本电脑后尝试运行笑话测试。以前,在计算机上,每个测试都在启动并且没有返回语法/运行时错误,但现在当我尝试在笔记本电脑上运行它们时,它们返回错误:
C:\PROJECT_DIR\foo.test.js
...initialState,
^^^
SyntaxError: Unexpected token ...
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:318:17)
是什么原因造成的?我做了npm install,一切都安装好了,但我一直收到这个错误,即使它没有出现在以前的机器上。
这是测试:
import increments from '../increments'
const initialState = {
goldBase: 0,
goldMulti: 1,
goldIncr: 0,
coalBase: 0,
coalMulti: 1,
coalIncr: 0,
ironBase: 0,
ironMulti: 1,
ironIncr: 0,
stoneBase: 0,
stoneMulti: 1,
stoneIncr: 0,
woodBase: 0,
woodMulti: 1,
woodIncr: 0,
foodBase: 0,
foodMulti: 1,
foodIncr: 0
}
describe('increments', () => {
it('should properly increment values of base increments', () => {
const action = {
type: 'INCREMENT',
goldBase: 1,
coalBase: 0.2,
ironBase: 0.8,
stoneBase: NaN,
woodBase: undefined,
foodBase: null
};
const testState = {
...initialState,
coalBase: 0.1
};
const expectedState = {
...initialState,
goldBase: 1,
coalBase: 0.3,
ironBase: 0.8,
};
expect(increments(testState, action)).toEqual(expectedState);
});
这里是package.json:
{
"name": "foo",
"version": "0.1.0",
"description": "",
"private": true,
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.6",
"react-scripts": "1.1.0",
"redux": "^3.7.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"test:watch": "npm test -- --watch",
"eject": "react-scripts eject"
},
"author": "",
"license": "MIT",
"homepage": "",
"devDependencies": {
"babel-jest": "^22.1.0",
"babel-preset-es2015": "^6.24.1",
"jest": "^22.1.4"
},
"babel": {
"presets": [
"es2015"
]
}
}
【问题讨论】: