您的位置:首页 > Web前端 > JavaScript

Mocha+Unit.js操作实例代码

2017-04-22 00:00 676 查看
创建测试代码文件basic.js

var test=require("unit.js")
var obj = {
message : 'hello',
name    : 'Nico'
};
var str = 'Hello world';
// Structure of a request object.
// By example, provided by Express framework and other modules.
var req = {
headers: {
'content-type': 'application/json'
}
};
describe("test obj",function(){
it("hasProperty 01",function(){
test.object(obj).hasProperty('name');
});
it("hasProperty 02",function(){
test.object(obj).hasProperty('message', 'hello');
});
});
describe("test str",function(){
it("startsWith",function(){
test.string(str).startsWith('Hello');
});
it("contains",function(){
test.string(str).contains('world');
});
it("match",function(){
test.string(str).match(/[a-zA-Z]/);
});
});

describe("test req",function(){
it("hasHeader 01",function(){
test.value(req).hasHeader('content-type');
});
it("hasHeader 02",function(){
test.value(req).hasHeader('content-type', 'application/json');
});
it("hasHeaderJson",function(){
test.value(req).hasHeaderJson();
});
});
使用mocha basic.js响应如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: