Я делаю все как в руководстве от https://vue-test-utils.vuejs.org/. Но все еще не может обработать ошибку: Плагин / Предустановленные файлы не могут экспортировать объекты, только функции. В /home/myApp/node_modules/babel-preset-stage-2/lib/index.js. Я пробовал разные способы исправить это, но оба сработали. Вот мой package.json
:
{
"name": "pangea-api",
"version": "1.0.0",
"description": "pangea api/admin",
"author": "wellyes",
"private": true,
"scripts": {
"dev": "API_URL='http://localhost:3001' node build/dev-server.js",
"start": "node build/dev-server.js",
"build": "API_URL='https://admin.pangea.global' node build/build.js",
"watch": "API_URL='http://localhost:3001' node build/watch.js",
"test": "jest"
},
"dependencies": {
"archiver": "^3.0.0",
"axios": "^0.18.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.2",
"connect-mongo": "^2.0.1",
"cookie-parser": "^1.4.3",
"cookie-session": "^2.0.0-beta.3",
"dotenv": "^6.1.0",
"excel-as-json": "^2.0.2",
"express-session": "^1.15.6",
"file-saver": "^1.3.8",
"file-type": "^8.0.0",
"form-data": "^2.3.2",
"fs-extra": "^7.0.0",
"generate-password": "^1.4.2",
"html-entities": "^1.2.1",
"html-word-count": "^2.0.0",
"jsonwebtoken": "^8.3.0",
"moment": "^2.21.0",
"mongoose": "^5.7.5",
"morgan": "^1.9.1",
"multer": "^1.3.0",
"mv": "^2.1.1",
"nan": "^2.10.0",
"node-sass": "^4.9.0",
"nodemailer": "^4.6.4",
"normalize.css": "^8.0.0",
"path": "^0.12.7",
"popper.js": "^1.12.9",
"pug": "^2.0.3",
"request": "^2.87.0",
"sass-loader": "^6.0.7",
"translate": "^1.0.2",
"unirest": "^0.5.1",
"vue": "^2.5.2",
"vue-click-outside": "^1.0.7",
"vue-lodash": "^2.0.0",
"vue-resource": "^1.5.0",
"vue-router": "^3.0.1",
"vuejs-datepicker": "^0.9.29",
"vuex": "^3.0.1",
"write": "^1.0.3",
"xml2json": "^0.11.2",
"xmlhttprequest": "^1.8.0"
},
"devDependencies": {
"@babel/core": "^7.7.7",
"@vue/test-utils": "^1.0.0-beta.30",
"autoprefixer": "^7.1.2",
"babel-jest": "24.9.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chalk": "^2.4.1",
"connect-history-api-fallback": "^1.5.0",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"cssnano": "^3.10.0",
"eventsource-polyfill": "^0.9.6",
"express": "^4.16.3",
"extract-text-webpack-plugin": "^2.0.0",
"file-loader": "^0.11.1",
"friendly-errors-webpack-plugin": "^1.1.3",
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"jest": "^24.9.0",
"nodemon": "^1.17.5",
"opn": "^5.1.0",
"optimize-css-assets-webpack-plugin": "^2.0.0",
"ora": "^1.2.0",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.2.5",
"url-loader": "^1.0.1",
"vue-jest": "^3.0.5",
"vue-loader": "^13.0.4",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.4.2",
"webpack": "^3.8.0",
"webpack-bundle-analyzer": "^2.11.3",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.22.2",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 4.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
}
}
}
А это мой .babelrc
:
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"],
"node": "current"
}
}],
"stage-2"
],
"plugins": ["transform-runtime"],
"env": {
"test": {
"presets": [["env", { "targets": { "node": "current" } }]],
"plugins": ["istanbul"]
}
}
}
Простой тестовый файл __tests__/firsttest.spec.js
:
import { mount } from '@vue/test-utils'
import Sidebar from '@/components/Sidebar'
describe('Sidebar', () => {
test('является экземпляром Vue', () => {
const wrapper = mount(Sidebar)
expect(wrapper.isVueInstance()).toBeTruthy()
})
})
Что я делаю не так?