我目前正在测试响应对象中是否存在一个属性。但是如果它不存在,那么下一个测试就会使整个程序崩溃,因为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();
});发布于 2014-02-06 15:38:05
我遇到了一个简单的解决办法,试着抓住。
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();
});https://stackoverflow.com/questions/21606866
复制相似问题