运行Jest / React测试时出现意外令牌错误

时间:2017-10-25 16:08:45

标签: reactjs configuration jest

我正在运行jest / react测试并收到以下错误:

/Users/sn/Documents/react-testing-with-jest-master/starter/CountdownTimer/jest.config.js:2
    "moduleFileExtensions": [
                          ^

SyntaxError: Unexpected token :

npm ERR! Test failed.  See above for more details.

这是我的jest.config.js:

{
    "moduleFileExtensions": [
        "js",
        "jsx"
    ],
    "moduleNameMapper": {
        "Clock": "<rootDir>/app/components/Clock.jsx",
        "CountdownForm": "<rootDir>/app/components/CountdownForm.jsx",
        "Countdown": "<rootDir>/app/components/Countdown.jsx"
    }
}

1 个答案:

答案 0 :(得分:0)

由于您已将文件命名为jest.config.js而不是jest.config.json,因此您需要导出有效的JavaScript对象。

或者:

  1. 将文件重命名为jest.config.json
  2. 导出有效的JS对象:
  3. jest.config.js

    {
        moduleFileExtensions: [
            "js",
            "jsx"
        ],
        moduleNameMapper: {
            Clock: "<rootDir>/app/components/Clock.jsx",
            CountdownForm: "<rootDir>/app/components/CountdownForm.jsx",
            Countdown: "<rootDir>/app/components/Countdown.jsx"
        }
    }