量角器:Return 来自原型的中继器计数

Protractor: Return Repeater Count from Prototype

我有这种我无法理解的行为:

Cart.prototype.getCouponsCount = function() {

    // Loop through all rows of coupons currently available in the cart
    ele.cartCouponsList.count().then(function(count) {

        console.log("Amount of items in cart:", count);
        return count;
    });
};

当这样调用时:

var Cart = require("../../../../lib/cartlib");
var cart = new Cart();

expect(cart.getCouponsCount()).toBe(2);

Returns undefined,但在控制台中我可以看到正在打印正确的优惠券金额。所以它只是不返回计数。

同样,我在 getText() 方法中使用了此方法,因此我不明白为什么 count() 方法的行为会有所不同。

工作方式:

Cart.prototype.getEvent = function(row) {

    var cartHistory = new Cart();
    var parent = cartHistory.getCartCoupon(row);

    var child = parent.element(by.binding("selection.event.name"))
        .getText().then(function(e) {

            console.log(e);
            return e;
        });
};

谁能给我指出正确的方向?

从函数中没有return,添加一下:

Cart.prototype.getCouponsCount = function() {

    // HERE 
    return ele.cartCouponsList.count().then(function(count) {

        console.log("Amount of items in cart:", count);
        return count;
    });
};