javascript - Making both parts of expect resolve promises -


the problem:

in protractor, expect() patched implicitly understand promises enables shorthand assertion style. e.g.:

expect(elm.gettext()).toequal("expected text"); 

elm.gettext() here not need explicitly resolved then() , implicitly resolved protractor before expectation checked.

but, if "to equal" part promise. instance, text element. in case have resolve second part explicitly:

elm2.gettext().then(function (text2) {     expect(elm1.gettext()).toequal(text2); }); 

the question:

is possible patch jasmine/protractor make understand promises on both sides of assertion? able write:

expect(elm1.gettext()).toequal(elm2.gettext()); 

just tested promises both sides - , resolves them ok. try @ project. maybe have nothing do:

describe('ololo', function () {  it('both sides 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, can see resolved promises     expect(elementtext1).toequal(elementtext2); });  }); 

if not work - think can use protractor.promise.all, example:

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

or harder way - create own matchers. see how work promises inside matcher in lib: https://github.com/xotabu4/jasmine-protractor-matchers/blob/master/index.js#l39


Comments