Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 2.11 KB

array-callback-return.md

File metadata and controls

57 lines (42 loc) · 2.11 KB

Enforce return statements in callbacks of ElementArrayFinder methods

ElementArrayFinder has multiple methods for filtering, mapping, reducing:

The callbacks for these methods have to return something for the method to work properly.

This rule would issue a warning if there is no return statement detected in the callback.

Known Limitations

This rule checks callback functions of methods with the given names only if called on element.all() or $$() explicitly. This means, that if there is, for example, a page object field which is later filtered:

myPage.rows.filter(function (row) {
    row.getText();
});

it would not be detected as a violation. Look into having array-callback-return built-in ESLint rule enabled to catch these cases.

Rule details

👎 Any use of the following patterns are considered warnings:

element.all(by.css(".myclass")).filter(function() {
  elm.getText().then(function (text) { 
    return text.indexOf("test") >= 0;
  })
});

$$(".myclass").filter(function cb() { if (a) return true; });
element(by.id("myid")).$$(".myclass").filter(function() { switch (a) { case 0: break; default: return true; } });
$$(".myclass").filter(function() { return; });
$$(".myclass").filter(function() { if (a) return; else return; });
$$(".myclass").filter(a ? function() {} : function() {});
$$(".myclass").filter(function(){ return function() {}; }())

👍 The following patterns are not warnings:

element.all(by.css(".myclass")).filter(function(elm) { 
  return elm.getText().then(function (text) { 
    return text.indexOf("test") >= 0;
  })
});

$$(".myclass").reduce(function() { return true; });
$$(".myclass").reduce(function() { switch (a) { case 0: bar(); default: return true; } })
var elements = element.all(by.css(".myclass"));