Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.2 KB

use-count-method.md

File metadata and controls

42 lines (30 loc) · 1.2 KB

Recommend using count() instead of then() and length

When you need to assert how many elements were found, it is more readable and easier when you do it using count():

expect(element.all(by.repeater('product in products')).count()).toBeGreaterThan(1);

instead of resolving the ElementArrayFinder value and getting the .length property:

element.all(by.repeater('product in products')).then(function (products) {
    expect(products.length >= 1).toBeTruthy();
});

Rule details

👎 Any use of the following patterns are considered warnings:

element.all(by.repeater('product in products')).then(function (products) {
    expect(products.length >= 1).toBeTruthy();
});

element.all(by.repeater('product in products')).then(function (products) {
    expect(10).toEqual(products.length);
});

👍 The following patterns are not warnings:

expect(element.all(by.repeater('product in products')).count()).toBeGreaterThan(1);

var products = [];
console.log(products.length);

element.all(by.repeater('product in products')).then(function (products) {
   console.log('test'); 
});