Mocha+Unit.js操作实例代码

来源:互联网 发布:中国男性阴茎 知乎 编辑:程序博客网 时间:2024/06/16 12:52

创建测试代码文件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响应如下:



0 0
原创粉丝点击