【问题标题】:Error: Invalid Chai property: toBe. Did you mean "to"?错误:无效的 Chai 属性:toBe。您指的是 “to” 吗?
【发布时间】:2018-08-29 12:47:26
【问题描述】:

我正在尝试检查某个元素是否存在于 Angular 网站中。我正在使用量角器 5.4.0。

在 my_steps.js 文件的标题中,我有这个:

global.expect = require('chai').expect
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

我用来断言下拉菜单存在的代码是:

Then(/^(.*) is present$/, function (dropdown,callback) {
        expect(element(by.id(dropdown)).isPresent()).toBe(true);
        callback();

protractor protractor.conf.js 命令的输出是:

When application opened # ../Features/step_definitions/my_steps.js:62
   ✖ Then templateSelection is present # ../Features/step_definitions/my_steps.js:70
       Error: Invalid Chai property: toBe. Did you mean "to"?

我做错了什么?

提前致谢。

【问题讨论】:

    标签: javascript protractor chai cucumberjs


    【解决方案1】:

    当您使用“chai-as-promised”插件时,该插件使用流利的语言扩展 Chai 以断言有关承诺的事实。您确实必须稍微调整断言。下面的页面给出了很好的例子。 Chai as promised page with explanations

    对于您的问题,您需要进行更改:

    .isPresent()).toBe(true);

    到:

    .isPresent()).to.eventually.equal(true);

    因此你的断言应该是这样的:

    expect(element(by.id(dropdown)).isPresent()).to.eventually.equal(true);

    另请注意,我没有看到仅使用.equals .equal

    【讨论】:

      【解决方案2】:

      isPresent() 返回一个承诺

      expect(element(by.id(dropdown)).isPresent()).to.eventually.equals(true);

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-19
        • 2019-01-30
        • 1970-01-01
        • 2019-07-01
        • 2019-08-28
        • 2019-06-23
        • 2018-01-01
        • 2018-05-30
        相关资源
        最近更新 更多