Skip to content Skip to sidebar Skip to footer

Making Both Parts Of Expect Resolve Promises

The Problem: In Protractor, expect() is patched to implicitly understand promises which enables a shorthand assertion style. E.g.: expect(elm.getText()).toEqual('expected text');

Solution 1:

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 promisesexpect(elementText1).toEqual(elementText2);
});

});

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')

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

Solution 2:

Not pretty, but you could resolve the param. It's a no-op for non promises...

expect(elm1.getText()).toEqual(Promise.resolve(elm2.getText()));

Post a Comment for "Making Both Parts Of Expect Resolve Promises"