什么是“待定”测试意味着摩卡,我怎么可以让它通过/失败?

问题描述 投票:3回答:4

我正在我的测试,发现:

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!`)
}
  • 什么是“待定”是什么意思?测试怎么可能是“待定”时摩卡已退出和节点不再运行?
  • 为什么这个测试不超时?
  • 我怎样才能使测试通过或失败?

谢谢!

javascript unit-testing mocha
4个回答
4
投票

测试可以最终被所示摩卡为“待定”当你不经意间关闭了测试的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...
});

2
投票

在许多测试框架挂起的测试是测试亚军决定不跑。有时是因为测试被标记被跳过。有时因为测试是一个TODO一个只是一个占位符。

对于摩卡的documentation说,一个负载测试是一个没有任何回调的测试。

你确定你正在寻找良好的测试?


1
投票

测试had a callback(即实际功能,没有这样做),但重构代码解决了问题。问题是如何的代码,预计误差应运行:

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

0
投票

当我这个问题所面临的悬而未决的错误是,当我定义与跳跃一个描述测试,忘了删除,这样的:

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

并没有运行它,我得到的输出

Pending test 'good test'

当我卸下描述测试跳过标记,它再次工作..

© www.soinside.com 2019 - 2024. All rights reserved.