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

相关文章
相关标签/搜索