【发布时间】:2013-11-14 23:48:58
【问题描述】:
我正在尝试使用 vows js 来创建单元测试。当“主题”是“未定义”时,我遇到了麻烦。请看下面的例子:
var vows = require('vows'),
assert = require('assert');
function giveMeUndefined(){
return undefined;
}
vows.describe('Test vow').addBatch({
'When the topic is undefined': {
topic: function() {
return giveMeUndefined();
},
'should return the default value of undefined.': function(topic) {
assert.isUndefined(topic);
}
}
}).export(module);
这不是确切的代码,但它是它的要点。当我运行测试时,我得到“回调未触发”。单步浏览 vows 的代码,我可以看到它在 topic 为undefined 时分支。
最终我想知道如何编写单元测试来做到这一点。我团队中的其他人写了我认为是 hack 的内容,并在主题中做了断言,如果 topic === undefined 则返回 true 或 false。
【问题讨论】:
标签: javascript node.js unit-testing vows