我正在尝试使用誓言js创建单元测试。当“主题”未定义时,我遇到了麻烦。请看下面的例子:未定义的誓言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);
这不完全是代码,但它是它的要点。当我运行测试时,我得到“回调未被解雇”。通过誓言的代码,当主题为undefined
时,我可以看到它的分支。
最终我想知道如何编写单元测试来做到这一点。我团队中的其他人写了我认为是黑客行为并做了主题断言并返回true
或false
如果topic === undefined
。