问题描述
如何设置Karma以运行后端单元测试(使用Mocha编写)?如果我将后端测试脚本添加到files = []
,它将无法说明未定义require
.
How do I setup Karma to run my backend unit tests (written with Mocha)? If I add my backend test script to the files = []
, it fails stating that require
is undefined.
推荐答案
您没有.业力仅用于测试基于浏览器的代码.如果您的项目在后端具有mocha测试,而在前端具有karma/mocha,请尝试在脚本下编辑package.json以将测试设置为:mocha -R spec && karma run karma.con
You don't. Karma is only for testing browser-based code. If you have a project with mocha tests on the backend and karma/mocha on the front end, try editing your package.json under scripts to set test to: mocha -R spec && karma run karma.con
然后,如果npm test
返回true,则将可以安全地进行提交或部署.
Then, if npm test
returns true, you'll know it's safe to commit or deploy.
这篇关于如何使用Karma测试Node.js后端代码(Testacular)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!