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

Add test for #106 #261

Merged
merged 1 commit into from
Oct 22, 2018
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
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);
});