gpt4 book ai didi

angular - TypeScript 和 chai-as-promisied : eventually is an invalid property

转载 作者:行者123 更新时间:2023-12-03 10:06:26 26 4
gpt4 key购买 nike

我正在尝试使用 TypScript 编写 Cucumber 测试,如下所示:

import { browser, $$ } from 'protractor';
import { Given, Then } from 'cucumber'
import { expect } from 'chai';

Given('I navigate to the homepage', function (callback) {
browser.get('http://localhost:4200');
callback();
});

Then('I want to see the welcome message {string}', function (message, callback) {
expect($$('h1').first().getText()).to.eventually.equal(message).and.notify(callback);
});

然而, Protractor 提示:

Error: Invalid Chai property: eventually



我怎样才能导入这个?我试过了:
import { eventual } from 'chai-as-promised';

但这不起作用。我怎样才能做到这一点?我也试过重写 Then使用 await 调用电话,但编译器提示您不能将回调与异步函数混合使用。啊!

最佳答案

在 Protractor 配置中,在 onPrepare 末尾添加以下行功能 :

onPrepare: function() {
...
// Load chai assertions
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');

// Load chai-as-promised support
chai.use(chaiAsPromised);

// Initialise should API (attaches as a property on Object)
chai.should();
}

使用异步函数时,您应该从函数签名中删除回调。
Then('I want to see the welcome message {string}',
async function (message) {
await chai.expect($$('h1').first().getText())
.to.eventually.equal(message);
});

关于angular - TypeScript 和 chai-as-promisied : eventually is an invalid property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52626679/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com