【发布时间】:2014-09-01 01:17:23
【问题描述】:
使用 NodeUnit 的要点之一是编写新函数并经常测试它们。问题是,如果其中一个测试函数抛出错误(包括 JS 运行时错误),则错误不会显示给用户。 这是最简单的测试用例:(注意 a.b.c.d 会导致运行时错误)
exports.all = {
one: function( test ){
test.done();
},
two: function( test ){
as( function( err, res ){
test.done();
});
},
}
function as( callback ){
process.nextTick( function() {
a = testMe();
callback( null, a );
});
}
function testMe(){
a.b.c.d.e = 100;
return 10;
}
不过,testMe() 可能是我正在开发的一个新函数。一个未初始化的变量,或任何东西,将保持沉默。
【问题讨论】:
标签: node.js mongodb unit-testing nodeunit