$ npm run test
> jest
FAIL test/unit/widget/window.test.js
● Test suite failed to run
Cannot find module 'babel-core'
找不到babel-core,当前项目中已经安装了@babel/core@7.3.4
执行命令npm i babel-core -D安装后再次测试
$ npm run test
> jest
FAIL test/unit/widget/window.test.js
● Test suite failed to run
Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.
原来babel-jest不支持babel7版本,后找到解决方案,需要安装babel-core@^7.0.0-bridge.0插件
卸载掉babel-core后安装npm i babel-core@^7.0.0-bridge.0 -D后再次测试
安装相关包:
npm i jest babel-jest vue-jest -D
在package.json里添加测试脚本:
配置
jest.config.js
文件:问题来了
找不到babel-core,当前项目中已经安装了@babel/core@7.3.4
执行命令
npm i babel-core -D
安装后再次测试原来babel-jest不支持babel7版本,后找到解决方案,需要安装
babel-core@^7.0.0-bridge.0
插件 卸载掉babel-core后安装npm i babel-core@^7.0.0-bridge.0 -D
后再次测试