断言是挂起而不是失败的CukeJS测试

时间:2014-11-16 16:58:06

标签: assert cucumberjs

我有以下断言......

        promise.then(function() {
                  assert.ok(browser.query(addForm), "It should have the add form");
          callback();
            })

但是当我试图看到它变红时,我得到......

Possibly unhandled AssertionError: It should have the add form

并且测试套件无法再进一步了

1 个答案:

答案 0 :(得分:1)

如果在函数内抛出任何内容,Cucumber.js似乎有问题。我不确定你使用哪个断言框架,但我遇到了类似的问题,使用Chai期望我传递给then()的回调。我通过在回调之外拉出预期来解决这个问题,如here所示。

修改,包括来自链接的代码:

例如,如果你使用Chai,你的代码看起来像这样:

element(by.tagName('body')).getText().then(function (text) {
  text = doSomethingSpecial(text);
  expect(text).to.equal('something');
});

您可以使用了解承诺的库(例如在本例中为chai-as-promise)修改您的代码,以便它看起来像:

var text = element(by.tagName('body')).getText().then(function (text) {
  return doSomethingSpecial(text);
});
expect(text).to.eventually.equal('something');
相关问题