javascript - 如何在课堂上编写摩卡测试
问题描述
是否可以在类中编写 mocha 测试,例如:
class test
{
// mocha test
describe("test goes here", function(){
it("sample test", function(){})
})
}
在这种情况下如何触发测试?
解决方案
必须同步定义测试mocha
才能收集您的测试。
index.test.js
:
const expect = require("chai").expect;
class Test {
run() {
describe("test goes here", function() {
it("sample test", function() {
expect(1 + 1).to.be.eq(2);
});
});
}
}
new Test().run();
试验结果:
test goes here
✓ sample test
1 passing (5ms)
---------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
index.test.js | 100 | 100 | 100 | 100 | |
---------------|----------|----------|----------|----------|-------------------|
源代码:https ://github.com/mrdulin/mocha-chai-sinon-codelab/tree/master/src/stackoverflow/59984203
推荐阅读
- dojo - DOJO TOOLKIT 中的 THEMES/CLARO.CSS 的哪个属性显示了按钮 DIJIT/FORM/BUTTON 内的文本框?
- android - 在 AppWidgetProvider 中注册 ContentObserver 以更新 AppWidget 不起作用
- flask - 如何在 Heroku 上启动我的 Flask 应用程序实例
- c - 堆栈上的局部变量(C)
- mariadb - 如何在 Galera 集群中创建非主组件进行测试
- bash - 带有条件的 gsutil 文件夹列表
- json - AHK 解析 JSON 数据
- excel - VBA:复制行并转置为列时剩余空间过多
- flutter - Flutter - 如何开始列表中的下一个倒计时
- r - 如何从包含特定字符串的数据框中获取列号?