Skip to content

Commit

Permalink
bindDataTestAttributes: Deprecate the automatic attribute bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed May 14, 2021
1 parent 240bc5d commit 8e98cdc
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion 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 @@ -39,6 +39,16 @@ export default function bindDataTestAttributes(component) {

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);
}
}
Expand All @@ -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;
}
}

0 comments on commit 8e98cdc

Please sign in to comment.