DRYing up visibility logic
MODIFY
tests/test-helper.js
tests/test-helper.js
@@ -4,13 +4,17 @@ import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-cli-qunit';
import QUnit from 'qunit';
+function isVisible(el) {
+ return el.offsetWidth !== 0 || el.offsetHeight !== 0 || el.getClientRects().length !== 0;
+}
+
QUnit.extend(QUnit.assert, {
isVisible: function(el, message) {
- let result = el !== null && !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
+ let result = el !== null && isVisible(el);
this.pushResult({ result, actual: result, expected: true, message });
},
isNotVisible: function(el, message) {
- let result = el === null || !(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
+ let result = el === null || !isVisible(el);
this.pushResult({ result, actual: result, expected: true, message });
}
});

DRYing up visibility logic