Skip to content

Commit 37b5b24

Browse files
author
Daniel Gröger
committed
make THEN step for visibility ignore irrelevant invisible elements
when checking that COUNT elements are in/visible do not check the count of all found element but rather the count of those that are visible or invisible. This also allows to combine providing the COUNT with using the NOT option, e.g. `then 10 elements should not be visible`. (cherry picked from commit 1157405)
1 parent 1454166 commit 37b5b24

File tree

1 file changed

+13
-12
lines changed
  • addon-test-support/-private/steps

1 file changed

+13
-12
lines changed

addon-test-support/-private/steps/then.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,21 @@ const steps = {
6464
},
6565

6666
"Then (?:(\\d+) )?$opinionatedElement should (not |NOT )?be visible"(countRaw, [collection/* , label, selector */], no) {
67-
assert(`Don't use NOT and number at the same time`, !(no && countRaw));
68-
69-
let count =
70-
no ? 0 :
67+
const count =
7168
countRaw ? parseInt(countRaw, 10) :
7269
1;
73-
74-
let m = `Element count`;
75-
expect(collection, m).to.have.length(count);
76-
77-
collection.forEach((element, i) => {
78-
m = `Element #${i} (zero-indexed) visibility`;
79-
expect(isVisible(element), m).to.be.true;
80-
});
70+
const countVisible = collection.filter(element => isVisible(element)).length;
71+
if (no) {
72+
if (countRaw !== undefined) {
73+
// check exact match of invisible elements
74+
expect(collection.length - countVisible, 'Invisible element count').to.equal(count);
75+
} else {
76+
// check no element is visible
77+
expect(countVisible, 'Visible element count').to.equal(0);
78+
}
79+
} else {
80+
expect(countVisible, 'Visible element count').to.equal(count);
81+
}
8182
},
8283

8384
"Then I should see (NO |no )?(?:(\\d+) )?$opinionatedElement"(no, countRaw, [collection, label, selector]) {

0 commit comments

Comments
 (0)