Skip to content

Commit

Permalink
utils/bind-data-test-attributes: Convert string to array if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Jan 11, 2017
1 parent 7868eda commit f48e6ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addon/utils/bind-data-test-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default function bindDataTestAttributes(component) {

let attributeBindings = component.getWithDefault('attributeBindings', []);

if (!Ember.isArray(attributeBindings)) {
attributeBindings = [attributeBindings];
}

for (let attr in component) {
if (TEST_SELECTOR_PREFIX.test(attr)) {
attributeBindings.push(attr);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/utils/bind-data-test-attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ test('it adds to existing attributeBindings array', function(assert) {
['foo', 'bar', 'data-test-from-invocation', 'data-test-from-factory']);
});

test('it converts existing attributeBindings string to array', function(assert) {
let Fixture = Ember.Object.extend({
attributeBindings: 'foo',

foo: 1,

'data-test-from-factory': 'foo',
});
let instance = Fixture.create({
'data-test-from-invocation': 'bar',
});

assert.deepEqual(instance.get('attributeBindings'), 'foo');

bindDataTestAttributes(instance);

assert.deepEqual(instance.get('attributeBindings'),
['foo', 'data-test-from-invocation', 'data-test-from-factory']);
});

test('it only adds data-test-* properties', function(assert) {
let Fixture = Ember.Object.extend({
foo: 1,
Expand Down

0 comments on commit f48e6ad

Please sign in to comment.