Skip to content

Commit

Permalink
Early exit if supportsDataTestProperties is set and component is tag-…
Browse files Browse the repository at this point in the history
…less
  • Loading branch information
Santosh Sutar authored and Turbo87 committed Mar 15, 2019
1 parent 24a2510 commit f5660ab
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
22 changes: 12 additions & 10 deletions addon/utils/bind-data-test-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ export default function bindDataTestAttributes(component) {
return;
}

if (!component.get('supportsDataTestProperties')) {
let tagName = component.get('tagName');
let tagName = component.get('tagName');

let message = `ember-test-selectors could not bind data-test-* properties on ${component} ` +
`automatically because tagName is empty. If you did this intentionally, see ` +
`https://github.com/simplabs/ember-test-selectors#usage-in-computed-properties ` +
`for instructions on how to disable this assertion.`;

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

let message = `ember-test-selectors could not bind data-test-* properties on ${component} ` +
`automatically because tagName is empty. If you did this intentionally, see ` +
`https://github.com/simplabs/ember-test-selectors#usage-in-computed-properties ` +
`for instructions on how to disable this assertion.`;

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

let attributeBindings = component.getWithDefault('attributeBindings', []);
if (!isArray(attributeBindings)) {
attributeBindings = [attributeBindings];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ if (!config.stripTestSelectors) {
assert.dom('.test-link-to-block a').hasAttribute('data-test-foo', 'bar');
assert.dom('.test-link-to-inline a').hasAttribute('data-test-foo', 'bar');
});

test('it handles the tagless components without assert when `supportsDataTestProperties` is set', function(assert) {
assert.dom('.test12 div[data-test-with-boolean-value]').doesNotExist('data-test-with-boolean-value does not exist');
assert.dom('.test13 div[data-test-without-value]').doesNotExist('data-test-without-value does not exist');
});
}
9 changes: 9 additions & 0 deletions tests/dummy/app/components/tagless-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Component from '@ember/component';

export default Component.extend({
// we're explicitly setting attributeBindings here to test that
// we are correctly slice()ing the frozen array if it exists already
attributeBindings: [],
tagName: '',
supportsDataTestProperties: true,
});
6 changes: 5 additions & 1 deletion tests/dummy/app/templates/bind-test.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@

<div class="test-link-to-block">{{#link-to "index" data-test-foo="bar"}}Label{{/link-to}}</div>

<div class="test-link-to-inline">{{link-to "Label" "index" data-test-foo="bar"}}</div>
<div class="test-link-to-inline">{{link-to "Label" "index" data-test-foo="bar"}}</div>

<div class="test12">{{tagless-component data-test-with-boolean-value=true}}</div>

<div class="test13">{{tagless-component data-test-without-value}}</div>
4 changes: 4 additions & 0 deletions tests/dummy/app/templates/components/tagless-component.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"Please disperse. Nothing to see here." - Frank Drebin

This component only exists so we can convenietly use moduleForComponent for the
tests which check that data-test-* attributes are stripped.

0 comments on commit f5660ab

Please sign in to comment.