“待定”测试在摩卡中意味着什么,我怎样才能让它通过/失败?

新手上路,请多包涵

我正在运行我的测试并注意到:

 18 passing (150ms)
1 pending

我以前没见过这个。之前的测试要么通过,要么失败。超时导致失败。我可以看到哪个测试失败了,因为它也是蓝色的。但是它有超时时间。这是一个简化版本:

 test(`Errors when bad thing happens`), function(){
  try {
    var actual = doThing(option)
  } catch (err) {
    assert(err.message.includes('invalid'))
  }
  throw new Error(`Expected an error and didn't get one!`)
}

  • “待定”是什么意思? 当 Mocha 退出并且节点不再运行时,测试怎么会“挂起”?
  • 为什么这个测试没有超时?
  • 我怎样才能使测试通过或失败?

谢谢!

原文由 mikemaccana 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 402
2 个回答

测试 有一个回调(即一个实际的函数,未完成)但重构代码解决了这个问题。问题是预期错误的代码应该如何运行:

 test('Errors when bad thing happens', function() {
  var gotExpectedError = false;
  try {
    var actual = doThing(option)
  } catch (err) {
    if ( err.message.includes('Invalid') ) {
      gotExpectedError = true
    }
  }
  if ( ! gotExpectedError ) {
    throw new Error(`Expected an error and didn't get one!`)
  }
});

原文由 mikemaccana 发布,翻译遵循 CC BY-SA 3.0 许可协议

当您无意中提前关闭测试的 it 方法时,Mocha 可能最终将测试显示为“待定”,例如:

 // Incorrect -- arguments of the it method are closed early
it('tests some functionality'), () => {
  // Test code goes here...
};

it 方法的参数应包括测试函数定义,如:

 // Correct
it('tests some functionality', () => {
  // Test code goes here...
});

原文由 Jon Schneider 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题