jest 報錯 SyntaxError: Unexpected string

最近研究單元測試,使用 vue-cli3 新建的項目,而後一直報錯,其中錯誤以下vue

● Test suite failed to run

    /Users/lyc/Desktop/study/vue/vue-jest1/tests/unit/about.spec.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import "core-js/modules/es6.array.find";
                                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    SyntaxError: Unexpected string

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.14s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue-jest1@0.1.0 test:unit: `vue-cli-service test:unit`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the vue-jest1@0.1.0 test:unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/lyc/.npm/_logs/2019-06-19T04_20_25_882Z-debug.log

找了好久最終在 https://github.com/vuejs/vue-... 找到解決方案。node

須要使用 ./node_modules/jest/bin/jest.js --clearCach 或者 npm jest --clearCach,須要清除緩存?git

而後再執行 npm run test:unit, 就能夠了。es6

爲了不每次都須要手動清除,直接加載 package.json文件裏,github

"scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test:e2e": "vue-cli-service test:e2e",
    "test:unit": "jest --clearCache && vue-cli-service test:unit"
  },

這裏添加 jest --ClearCach 便可。vue-cli

相關文章
相關標籤/搜索