首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使nodeunit报告以前的错误?

如何使nodeunit报告以前的错误?
EN

Stack Overflow用户
提问于 2014-02-06 15:21:35
回答 1查看 59关注 0票数 0

我目前正在测试响应对象中是否存在一个属性。但是如果它不存在,那么下一个测试就会使整个程序崩溃,因为test.done()永远不会被调用。

代码语言:javascript
复制
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语句,但它似乎太麻烦了。

代码语言:javascript
复制
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();

});
EN

回答 1

Stack Overflow用户

发布于 2014-02-06 15:38:05

我遇到了一个简单的解决办法,试着抓住。

代码语言:javascript
复制
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();

});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21606866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档