在jasmine或mocha中声明"待定"规范/测试

WHI*_*LOR 36 mocha.js jasmine

我想描述应该在代码中的规范,但稍后会添加它们的实现.在测试结果中,我希望看到它们既不会通过也不会失败,而是"正在等待"实施.

如果有可能在摩卡或茉莉花中开箱即用,我很感兴趣.

谢谢

小智 61

您可以使用xit(而不是it)和xdescribe(而不是describe)在mocha和jasmine中声明禁用的函数.

如果您希望测试显示为挂起,则在mocha中,您可以在调用it()函数时将第二个参数留空.例如:

describe('Something', function () {
    it('Should be pending')
    xit('Should be disabled, i.e not appear on the list')
});
Run Code Online (Sandbox Code Playgroud)

更新:如果发生此合并,则可能会在Mocha中更改xit/ 的行为xdescribe:https://github.com/visionmedia/mocha/pull/510

  • 测试运行器如何将它们标记为待处理?AFAIK,jasmine将它们显示为"通行证"? (2认同)
  • [在Jasmine 1.5中]`it()`没有第二个参数显示为传递,我不会考虑等待.`xit()`和`xdescribe()`(后者需要一个函数第二个参数)没有待处理; 它们完全被忽略,在UI中没有提到.`this.fail('message');`将手动失败测试; 也没有待定.Jasmine v2显然会有一个真正的"待定"状态. (2认同)

Sve*_*cke 22

从Jasmine 2.0开始,编写xit()而不是it()规范将其标记为待定(正如在已接受的答案的评论中已经说过的那样).

另外,pending()您可以在规范中的任何位置调用函数将其标记为挂起:

it("can be declared by calling 'pending' in the spec body", function() {
  expect(true).toBe(false);
  pending();
});
Run Code Online (Sandbox Code Playgroud)

另请参阅Jasmine 2.0中有关挂起规范文档.

  • `pending(“这是它待处理的原因”);` (2认同)

law*_*nce 15

在mocha中,您还可以使用skip:

describe('my module', function() {
  it.skip('works', function() {
    // nothing yet
  });
});
Run Code Online (Sandbox Code Playgroud)

您也describe.skip可以跳过整个部分.

  • `describe.skip()` 和 `it.skip()` 比 `xdescribe` 和 `xit` 干净得多 (2认同)