Skip to content

Commit

Permalink
Merge pull request #713 from Turbo87/deprecate-auto-bindings
Browse files Browse the repository at this point in the history
Deprecate automatic attribute bindings
  • Loading branch information
Turbo87 authored May 14, 2021
2 parents a9708fc + 8e98cdc commit 951178b
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions addon/utils/bind-data-test-attributes.js
Original file line number Diff line number Diff line change
@@ -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-.*/;
Expand Down Expand Up @@ -37,7 +37,21 @@ export default function bindDataTestAttributes(component) {
attributeBindings = attributeBindings.slice();
}

dataTestProperties.forEach(it => attributeBindings.push(it));
for (let prop of dataTestProperties) {
if (attributeBindings.indexOf(prop) === -1) {
let componentName = extractComponentName(component) || `<unknown>`;
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);
}
}

try {
component.set('attributeBindings', attributeBindings);
Expand All @@ -51,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;
}
}

0 comments on commit 951178b

Please sign in to comment.