Skip to content

Commit

Permalink
Fix tests for Ember < 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Feb 5, 2018
1 parent 28f534e commit 8de0ee5
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions tests/integration/components/dummy-component-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { expect } from 'chai';
import { describe, it, beforeEach } from 'mocha';
import { setupComponentTest } from 'ember-mocha';
import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';

// imported from https://github.com/emberjs/ember-test-helpers/blob/v0.7.16/addon-test-support/%40ember/test-helpers/has-ember-version.js
function hasEmberVersion(major, minor) {
let numbers = Ember.VERSION.split('-')[0].split('.');
let actualMajor = parseInt(numbers[0], 10);
let actualMinor = parseInt(numbers[1], 10);
return actualMajor > major || (actualMajor === major && actualMinor >= minor);
}

describe('HBS Minifier plugin', function() {
setupComponentTest('dummy-component', { integration: true });

Expand All @@ -14,18 +23,35 @@ describe('HBS Minifier plugin', function() {
this.render(hbs`{{foo}} \n\n \n{{bar}}`);

let childNodes = this.$()[0].childNodes;
expect(childNodes).to.have.lengthOf(3);
expect(childNodes[1]).to.be.a('text');
expect(childNodes[1]).to.have.a.property('textContent', ' ');

if (hasEmberVersion(2, 10)) {
expect(childNodes).to.have.lengthOf(3);
expect(childNodes[1]).to.be.a('text');
expect(childNodes[1]).to.have.a.property('textContent', ' ');
} else {
expect(childNodes).to.have.lengthOf(5);
expect(childNodes[2]).to.be.a('text');
expect(childNodes[2]).to.have.a.property('textContent', ' ');
}
});

it('strips leading and trailing whitespace from Program nodes', function() {
this.render(hbs` {{foo}} `);

let childNodes = this.$()[0].childNodes;
expect(childNodes).to.have.lengthOf(1);
expect(childNodes[0]).to.be.a('text');
expect(childNodes[0]).to.have.a.property('textContent', 'foo');
if (hasEmberVersion(2, 10)) {
expect(childNodes).to.have.lengthOf(1);
expect(childNodes[0]).to.be.a('text');
expect(childNodes[0]).to.have.a.property('textContent', 'foo');
} else {
expect(childNodes).to.have.lengthOf(3);
expect(childNodes[0]).to.be.a('text');
expect(childNodes[0]).to.have.a.property('textContent', '');
expect(childNodes[1]).to.be.a('text');
expect(childNodes[1]).to.have.a.property('textContent', 'foo');
expect(childNodes[2]).to.be.a('text');
expect(childNodes[2]).to.have.a.property('textContent', '');
}
});

it('Collapse leading/trailing text from Program nodes into a single whitespace', function() {
Expand Down

0 comments on commit 8de0ee5

Please sign in to comment.