From 46fcd512f77e970b44ca8939383ebf0242a84451 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 14 May 2021 11:35:28 +0200 Subject: [PATCH 1/3] bindDataTestAttributes: Convert `forEach()` to `for..of` loop --- addon/utils/bind-data-test-attributes.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addon/utils/bind-data-test-attributes.js b/addon/utils/bind-data-test-attributes.js index 5c87cdd9..ee3c3720 100644 --- a/addon/utils/bind-data-test-attributes.js +++ b/addon/utils/bind-data-test-attributes.js @@ -37,7 +37,9 @@ export default function bindDataTestAttributes(component) { attributeBindings = attributeBindings.slice(); } - dataTestProperties.forEach(it => attributeBindings.push(it)); + for (let prop of dataTestProperties) { + attributeBindings.push(prop); + } try { component.set('attributeBindings', attributeBindings); From 240bc5d05dd1702ff0663656225acb3ac6ebd94f Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 14 May 2021 11:36:58 +0200 Subject: [PATCH 2/3] bindDataTestAttributes: Avoid duplicated in `attributeBindings` --- addon/utils/bind-data-test-attributes.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addon/utils/bind-data-test-attributes.js b/addon/utils/bind-data-test-attributes.js index ee3c3720..219b1251 100644 --- a/addon/utils/bind-data-test-attributes.js +++ b/addon/utils/bind-data-test-attributes.js @@ -38,7 +38,9 @@ export default function bindDataTestAttributes(component) { } for (let prop of dataTestProperties) { - attributeBindings.push(prop); + if (attributeBindings.indexOf(prop) === -1) { + attributeBindings.push(prop); + } } try { From 8e98cdc221e5ff75d6fac1a1391ca96f44f6635a Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 14 May 2021 12:03:35 +0200 Subject: [PATCH 3/3] bindDataTestAttributes: Deprecate the automatic attribute bindings --- addon/utils/bind-data-test-attributes.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/addon/utils/bind-data-test-attributes.js b/addon/utils/bind-data-test-attributes.js index 219b1251..4b5b92bd 100644 --- a/addon/utils/bind-data-test-attributes.js +++ b/addon/utils/bind-data-test-attributes.js @@ -1,4 +1,4 @@ -import { assert } from '@ember/debug'; +import { assert, deprecate } from '@ember/debug'; import { isArray } from '@ember/array'; const TEST_SELECTOR_PREFIX = /data-test-.*/; @@ -39,6 +39,16 @@ export default function bindDataTestAttributes(component) { for (let prop of dataTestProperties) { if (attributeBindings.indexOf(prop) === -1) { + let componentName = extractComponentName(component) || ``; + deprecate(`You have set ${prop} on the ${componentName} component. Relying on automatic attribute binding of data-test properties on classic components is deprecated. Your options are:\n\n` + + '- use angle bracket syntax with `...attributes` to invoke components\n' + + '- explicitly add `attributeBindings` to the component\n' + + '- stay on an older version of ember-test-selectors\n\n', false, { + for: 'ember-test-selectors', + id: 'ember-test-selectors.auto-binding', + until: '6.0.0', + since: { available: '5.2.0', enabled: '5.2.0' }, + }); attributeBindings.push(prop); } } @@ -55,3 +65,15 @@ export default function bindDataTestAttributes(component) { }); } } + +function extractComponentName(component) { + let debugKey = component._debugContainerKey; + if (debugKey) { + return debugKey.replace(/^component:/, ''); + } + + let className = component.constructor.name; + if (className && className !== 'Class') { + return className; + } +}