gpt4 book ai didi

angularjs - 将 Promise 转为 int

转载 作者:行者123 更新时间:2023-12-02 23:10:40 27 4
gpt4 key购买 nike

这可能是一个愚蠢的问题,但是我很难找到我需要的答案。我有一个计算中继器的测试。我想返回 count 变量,以便我可以将其传递给另一个测试以在 for 循环中使用。

我尝试过的:

this.countsInitialBookings = function() {
var j = 0;
browser.driver.sleep(3000);
bookingLists = element.all(by.repeater('booking in bookingsCtrl.bookings'));
bookingLists.count().then(function(count) {
//have also tried making bookingCount global and setting value to 0
var bookingCount = count;
});
return bookingCount;
};

这就是吐出的Started

.{ closure_uid_966269928: 651,
flow_:
{ events_: {},
closure_uid_966269928: 1,
activeFrame_:
{ events_: {},
closure_uid_966269928: 642,
flow_: [Circular],
parent_: [Object],
children_: [Object],
lastInsertedChild_: [Object],
pendingTask_: null,
isLocked_: false,
isBlocked_: false,
pendingCallback: false,
pendingRejection: false,
cancellationError_: null },
schedulingFrame_:
{ events_: {},
closure_uid_966269928: 642,
flow_: [Circular],
parent_: [Object],
children_: [Object],
lastInsertedChild_: [Object],
pendingTask_: null,
isLocked_: false,
isBlocked_: false,
pendingCallback: false,
pendingRejection: false,
cancellationError_: null },
shutdownTask_: null,
eventLoopTask_: null,
hold_:
{ _idleTimeout: 2147483647,
_idlePrev: [Object],
_idleNext: [Object],
_idleStart: 99601735,
_onTimeout: [Function: wrapper],
_repeat: true },
yieldCount_: 1 },
stack_: null,
parent_:
{ closure_uid_966269928: 649,
flow_:
{ events_: {},
closure_uid_966269928: 1,
activeFrame_: [Object],
schedulingFrame_: [Object],
shutdownTask_: null,
eventLoopTask_: null,
hold_: [Object],
yieldCount_: 1 },
stack_: null,
parent_:
{ closure_uid_966269928: 647,
flow_: [Object],
stack_: null,
parent_: [Object],
callbacks_: [Object],
state_: 'pending',
handled_: true,
pendingNotifications_: false,
value_: undefined },
callbacks_: [ [Object] ],
state_: 'pending',
handled_: true,
pendingNotifications_: false,
value_: undefined },
callbacks_: null,
state_: 'pending',
handled_: false,
pendingNotifications_: false,
value_: undefined }
.


2 specs, 0 failures
Finished in 17.516 seconds
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed

Process finished with exit code 0

最佳答案

由于 .count() 是异步的,因此不可能从 countsInitialBookings 返回整数。相反,您应该返回 Promise,然后您可以稍后使用 Promise 来获取值。

this.countsInitialBookings = function() {
var j = 0;
browser.driver.sleep(3000);
bookingLists = element.all(by.repeater('booking in bookingsCtrl.bookings'));
return bookingLists.count()
};

稍后...

this.countsInitialBookings().then(function (count) {
console.log(count);
});
// do not attempt to get `count` out here, it's simply not possible.
// It will only be accessible inside the above callback.

关于angularjs - 将 Promise 转为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32126948/

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