From b7b12be12cc0c6f6b295f912ca43a18fb2d95555 Mon Sep 17 00:00:00 2001 From: Santosh Sutar Date: Thu, 21 Feb 2019 11:37:53 -0800 Subject: [PATCH] Add acceptance test --- addon/utils/bind-data-test-attributes.js | 4 ++-- .../bind-data-test-attributes-in-components-test.js | 5 +++++ tests/dummy/app/components/tagless-component.js | 9 +++++++++ tests/dummy/app/templates/bind-test.hbs | 6 +++++- .../dummy/app/templates/components/tagless-component.hbs | 4 ++++ 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/dummy/app/components/tagless-component.js create mode 100644 tests/dummy/app/templates/components/tagless-component.hbs diff --git a/addon/utils/bind-data-test-attributes.js b/addon/utils/bind-data-test-attributes.js index 14c19577..889e79dc 100644 --- a/addon/utils/bind-data-test-attributes.js +++ b/addon/utils/bind-data-test-attributes.js @@ -15,8 +15,9 @@ export default function bindDataTestAttributes(component) { return; } + let tagName = component.get('tagName'); + if (!component.get('supportsDataTestProperties')) { - 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 ` + @@ -36,7 +37,6 @@ export default function bindDataTestAttributes(component) { } dataTestProperties.forEach(it => attributeBindings.push(it)); - let tagName = component.get('tagName'); if (component.get('supportsDataTestProperties') && tagName === '') { return; 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..a281cc5e 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}}
\ No newline at end of file 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.