diff --git a/addon/utils/bind-data-test-attributes.js b/addon/utils/bind-data-test-attributes.js index ef52c00e..3bf685ef 100644 --- a/addon/utils/bind-data-test-attributes.js +++ b/addon/utils/bind-data-test-attributes.js @@ -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 = String(`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 = String(`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]; diff --git a/tests/acceptance/bind-data-test-attributes-in-components-test.js b/tests/acceptance/bind-data-test-attributes-in-components-test.js index d778a42d..017025e8 100644 --- a/tests/acceptance/bind-data-test-attributes-in-components-test.js +++ b/tests/acceptance/bind-data-test-attributes-in-components-test.js @@ -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'); + }); } diff --git a/tests/dummy/app/components/tagless-component.js b/tests/dummy/app/components/tagless-component.js new file mode 100644 index 00000000..c242cbe7 --- /dev/null +++ b/tests/dummy/app/components/tagless-component.js @@ -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, +}); diff --git a/tests/dummy/app/templates/bind-test.hbs b/tests/dummy/app/templates/bind-test.hbs index f1360b6d..ab4759ff 100644 --- a/tests/dummy/app/templates/bind-test.hbs +++ b/tests/dummy/app/templates/bind-test.hbs @@ -24,4 +24,8 @@ - \ No newline at end of file + + +
{{tagless-component data-test-with-boolean-value=true}}
+ +
{{tagless-component data-test-without-value}}
diff --git a/tests/dummy/app/templates/components/tagless-component.hbs b/tests/dummy/app/templates/components/tagless-component.hbs new file mode 100644 index 00000000..5b9b42c8 --- /dev/null +++ b/tests/dummy/app/templates/components/tagless-component.hbs @@ -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.