手动配置karma+mocha+chai 进行单元测试

1.package.json所需要引入的依赖包

"babel-plugin-istanbul": "^4.1.6",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-vue-jsx": "^3.7.0",
"babel-polyfill": "^6.26.0",
"chai": "^4.1.2",
"cross-env": "^5.2.0",
"jasmine-core": "^3.1.0",
"karma": "^2.0.5",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-jasmine": "^1.1.2",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-phantomjs-shim": "^1.5.0",
"karma-sinon-chai": "^2.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "^3.0.0",
"mocha": "^5.2.0",
"sinon": "^6.1.4",
"sinon-chai": "^3.2.0",

2.运行测试用例

"scripts": {
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run"
},

你可能感兴趣的:(单元测试)