Skip to content

Commit

Permalink
Merge pull request #261 from Turbo87/tagname-assertion
Browse files Browse the repository at this point in the history
Add test for #106
  • Loading branch information
Turbo87 authored Oct 22, 2018
2 parents 16e1408 + 5687fc1 commit 5ecdac1
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/unit/utils/bind-data-test-attributes-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { module, test } from 'qunit';
import EmberObject, { computed } from '@ember/object';
import EmberMixin from '@ember/object/mixin';
import { dasherize } from '@ember/string';

import bindDataTestAttributes from 'ember-test-selectors/utils/bind-data-test-attributes';

Expand Down Expand Up @@ -126,3 +128,49 @@ test('it breaks if tagName is empty', function(assert) {

assert.throws(() => bindDataTestAttributes(instance));
});

test('issue #106', function(assert) {
let Component = EmberObject.extend({});

Component.reopen({
init() {
this._super(...arguments);
bindDataTestAttributes(this);
},
});

let Mixin = EmberMixin.create({
init() {
this._super(...arguments);

if (this.tagName !== '') {
let componentName = dasherize(this._XXXdebugContainerKey.replace(/\//g, '-').split(':')[1]);
this.set('data-test-component', componentName);

let dataTestAttr = ['data-test-component'];
this.attributeBindings = this.attributeBindings ? this.attributeBindings.concat(dataTestAttr) : dataTestAttr;
}
},
});

Component.reopen(Mixin);

let Fixture1 = Component.extend({
_XXXdebugContainerKey: 'component:fixture1',
tagName: 'span',
});

let fixture1 = Fixture1.create();

assert.strictEqual(fixture1.get('data-test-component'), 'fixture1');

let Fixture2 = Component.extend({
_XXXdebugContainerKey: 'component:fixture2',
tagName: '',
});

let fixture2 = Fixture2.create();

assert.strictEqual(fixture2.get('data-test-component'), undefined);
});

0 comments on commit 5ecdac1

Please sign in to comment.