繁体   English   中英

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

[英]What does 'pending' test mean in Mocha, and how can I make it pass/fail?

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

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退出并且节点不再运行时,测试如何“挂起”?
  • 为什么这个测试没有超时?
  • 如何使测试通过或失败?

谢谢!

测试可以最终被所示摩卡为“待定”当你不经意间关闭了测试的it方法早,如:

// 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...
});

许多测试框架中的待测试是测试跑步者决定不运行。 有时这是因为测试被标记为跳过。 有时因为测试只是TODO的占位符。

对于Mocha, 文档说暂挂测试是没有任何回调的测试。

你确定你正在看好考试吗?

测试有一个回调 (即一个实际的功能,没有完成),但重构代码解决了这个问题。 问题是如何运行期望错误的代码:

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!`)
  }
});

当我遇到这个问题时,挂起的错误就是当我用skip定义一个describe测试时,忘了删除它,就像那样:

describe.skip('padding test', function () {
   it('good test', function () {
       expect(true).to.equal(true);
   })
});

并且确实运行了它,我得到了输出

Pending test 'good test'

当我在描述测试中删除跳过标志时,它再次起作用..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM