我目前正在测试响应对象中是否存在属性。但是如果它不存在,那么下一个测试就会让整个事情变成膝盖,因为test.done()永远不会被调用。
foo.execute( function( error, response ) {
test.ok( typeof response.request != 'undefined',
"The response should have a request property" );
test.equal( response.request.method, 'GET',
"The request header should reflect the method used." );
test.done();
});
结果是......
失败:未经测试(或他们的设置/拆卸): - PostResourseGetSucceeds
要解决此问题,请确保所有测试都调用test.done()
如何让测试仍然报告初始测试?我尝试过使用if语句,但这似乎很麻烦。
foo.execute( function( error, response ) {
test.ok( typeof response.request != 'undefined',
"The response should have a request property" );
if ( typeof response.request != 'undefined' ) {
test.equal( response.request.method, 'GET',
"The request header should reflect the method used." );
}
test.done();
});
答案 0 :(得分:0)
我找到了一个简单的解决方案,试着赶上。
foo.execute( function( error, response ) {
try {
test.ok( typeof response.request != 'undefined',
"The response should have a request property" );
test.equal( response.request.method, 'GET',
"The request header should reflect the method used." );
}
catch(e) {
test.ok( false, "Not all tests were run." );
};
test.done();
});