eslint-plugin-protractor icon indicating copy to clipboard operation
eslint-plugin-protractor copied to clipboard

Rule Proposal: Recommend to pass promises to expect() directly if possible

Open alecxe opened this issue 9 years ago • 0 comments

There is a common anti-pattern in Protractor when something is explicitly resolved and then asserted instead of passing a promise directly to expect() which is patched to understand promises and resolve them implicitly before making an expectation.

This should issue a warning:

element(by.css("#myid")).getText().then(function (text) {
    expect(text).toEqual("My Text");
});

This should be used instead:

expect(element(by.css("#myid")).getText()).toEqual("My Text");

I can imagine that this would not of course catch all the violations of the type, but I think, at the very least, the rule should look that the promise resolution functions argument (text in this case) is not then passed to expect()..

alecxe avatar Jul 10 '16 00:07 alecxe