Skip to content

Commit

Permalink
utils/bind-data-test-attributes: Handle failing set() with assert i…
Browse files Browse the repository at this point in the history
…nstead of warning (#205)

* utils/bind-data-test-attributes: Handle failing  with assert instead of warning

* Replaces integration tests with unit tests
  • Loading branch information
mathieupoteriepeopledoc authored and Turbo87 committed Sep 14, 2018
1 parent 14b7aab commit 6e245a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
15 changes: 6 additions & 9 deletions addon/utils/bind-data-test-attributes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { warn } from '@ember/debug';
import { assert, warn } from '@ember/debug';
import { isArray } from '@ember/array';

const TEST_SELECTOR_PREFIX = /data-test-.*/;
Expand All @@ -16,16 +16,13 @@ export default function bindDataTestAttributes(component) {
}

let tagName = component.get('tagName');
if (tagName === '') {
let message = `ember-test-selectors could not bind data-test-* properties on ${component} ` +
`automatically because tagName is empty.`;

warn(message, false, {
id: 'ember-test-selectors.empty-tag-name',
});
let message = `ember-test-selectors could not bind data-test-* properties on ${component} ` +
`automatically because tagName is empty.`;

return;
}
assert(message, tagName !== '', {
id: 'ember-test-selectors.empty-tag-name',
});

let attributeBindings = component.getWithDefault('attributeBindings', []);
if (!isArray(attributeBindings)) {
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/utils/bind-data-test-attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ test('it skips if attributeBindings is a computed property', function(assert) {
assert.deepEqual(instance.get('attributeBindings'), ['foo']);
});

test('it skips if tagName is empty', function(assert) {
test('it breaks if tagName is empty', function(assert) {
let Fixture = EmberObject.extend({
tagName: '',
'data-test-from-factory': 'foo',
Expand All @@ -128,9 +128,5 @@ test('it skips if tagName is empty', function(assert) {
'data-test-from-invocation': 'bar',
});

assert.deepEqual(instance.get('attributeBindings'), undefined);

bindDataTestAttributes(instance);

assert.deepEqual(instance.get('attributeBindings'), undefined);
assert.throws(() => bindDataTestAttributes(instance));
});

0 comments on commit 6e245a6

Please sign in to comment.