且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使两个部分都期望解决承诺

更新时间:2023-11-21 18:15:22

刚刚测试了双方的承诺 - 并且它结算了他们没事。
试试你的项目。也许你无事可做:

Just tested with promises for both sides - and it resolves them OK. Try at your project. Maybe you have nothing to do:

describe('ololo', function () {

it('both sides are promises', function () {
    browser.get('http://www.protractortest.org/testapp/ng1/#/form');

    let elementText1 = $('.ng-scope p').getText();

    let elementText2 = $('#transformedtext>h4').getText();

    //Will fail here, but you can see that it successfully resolved promises
    expect(elementText1).toEqual(elementText2);
});

});

如果这不适合你 - 我想你可以使用protractor.promise.all,只是一个例子:

If this does not work for you - i think you can use protractor.promise.all, just example:

protractor.promise.all([elm2.getText(), elm1.getText()])
        .then(texts=> expect(texts[0]).toEqual(texts[1]), 'texts should be same')

或更难的方式 - 创建自己的匹配器。看看我如何在我的lib中使用matcher里面的promises:
https://github.com/Xotabu4/jasmine-protractor-matchers/blob/master/index.js#L39

Or harder way - create own matchers. See how i work with promises inside matcher in my lib: https://github.com/Xotabu4/jasmine-protractor-matchers/blob/master/index.js#L39