gpt4 book ai didi

node.js - 测试总是超时,不显示 promise 输出

转载 作者:太空宇宙 更新时间:2023-11-03 22:11:17 25 4
gpt4 key购买 nike

        browser.sleep(4000);
var discount_type = element(by.id("discount_type"));
var discount_value= element(by.id("discount_value"));
var grandTotal = element(by.id("grand-total"));
var subtotal = element(by.id("subtotal"));
var delivery_fee = element(by.id("delivery_fee"));

var last = protractor.promise.defer();

console.log("hallo");
subtotal.getText().then(function(sub) {
console.log("#############");
console.log(sub);
delivery_fee.getText().then(function(fee) {
console.log(fee);
var calc = parseFloat(sub) - parseFloat(fee) - parseFloat(config.promocodes.referral.discount);
console.log(calc);
last.fulfill(calc);
});
});
last.then(function(calc) {
console.log("final wait");
expect(grandTotal.getText()).toBe("$" + calc);
});

我需要计算一个值才能确定我的测试运行正常。

在我的测试中,我总是能在控制台中看到“hallo”。然后我得到一个

> hallo
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
> F
>
> Failures: 1) Refer a user and apply referral code should assign
> referral discount to user Message:
> Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. Stack:
> Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
> at Timer.listOnTimeout (timers.js:92:15)

看起来代码从未进入subtotal.getText() promise !这是为什么???

最佳答案

永远不会从 promise 解析函数中返回。而且,您不必延迟:

var last = subtotal.getText().then(function(sub) {
return delivery_fee.getText().then(function(fee) {
return parseFloat(sub) - parseFloat(fee) - parseFloat(config.promocodes.referral.discount);
});
});
last.then(function(calc) {
expect(grandTotal.getText()).toBe("$" + calc);
});

关于node.js - 测试总是超时,不显示 promise 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41103018/

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