Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate automatic attribute bindings #713

Merged
merged 3 commits into from
May 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}