Skip to content

Commit

Permalink
Merge pull request #180 from trentmwillis/reset-element
Browse files Browse the repository at this point in the history
Reset ember-testing div to initial state on teardown
  • Loading branch information
rwjblue authored Sep 27, 2016
2 parents 77f9a53 + b94785f commit c392d85
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/ember-test-helpers/abstract-test-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ export default Klass.extend({
},

setupTestElements() {
if (!document.querySelector('#ember-testing')) {
let testEl = document.querySelector('#ember-testing');
if (!testEl) {
let element = document.createElement('div');
element.setAttribute('id', 'ember-testing');

document.body.appendChild(element);
this.fixtureResetValue = '';
} else {
this.fixtureResetValue = testEl.innerHTML;
}
},

Expand Down Expand Up @@ -135,7 +139,7 @@ export default Klass.extend({
},

teardownTestElements() {
document.getElementById('ember-testing').innerHTML = '';
document.getElementById('ember-testing').innerHTML = this.fixtureResetValue;

// Ember 2.0.0 removed Ember.View as public API, so only do this when
// Ember.View is present
Expand Down
40 changes: 40 additions & 0 deletions tests/test-module-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import test from 'tests/test-support/qunit-test';
import qunitModuleFor from 'tests/test-support/qunit-module-for';
import { setResolverRegistry, createCustomResolver } from 'tests/test-support/resolver';

// The fixture reset tests are order dependent
QUnit.config.reorder = false;

function moduleFor(fullName, description, callbacks) {
var module = new TestModule(fullName, description, callbacks);
qunitModuleFor(module);
Expand Down Expand Up @@ -347,3 +350,40 @@ moduleFor('component:y-foo', 'Custom resolver', {
test('subject created using custom resolver', function() {
equal(this.subject().name, 'Y u no foo?!');
});

moduleFor('component:x-foo', 'ember-testing resets to empty value');

test('sets ember-testing content to "foobar"', function() {
expect(0);
document.getElementById('ember-testing').innerHTML = 'foobar';
});

test('ember-testing content should be reset to ""', function() {
expect(1);
equal(document.getElementById('ember-testing').innerHTML, '');
});

QUnit.module('ember-testing resets to non-empty value');

test('sets ember-testing content to "<div>foobar</div>"', function() {
expect(0);
document.getElementById('ember-testing').innerHTML = '<div>foobar</div>';
});

test('sets ember-testing content to ""', function() {
expect(0);

module = new TestModule('component:x-foo', 'Foo');
module.setContext(this);
return module.setup(...arguments).then(() => {
document.getElementById('ember-testing').innerHTML = '';

return module.teardown(...arguments);
});
});

test('ember-testing content should be reset to "<div>foobar</div>"', function() {
expect(1);
equal(document.getElementById('ember-testing').innerHTML, '<div>foobar</div>');
document.getElementById('ember-testing').innerHTML = '';
});

0 comments on commit c392d85

Please sign in to comment.