From b94785f486dc83eae8218089b804aa759382f581 Mon Sep 17 00:00:00 2001 From: Trent Willis Date: Mon, 19 Sep 2016 09:35:39 -0700 Subject: [PATCH] Reset ember-testing div to initial state on teardown --- .../abstract-test-module.js | 8 +++- tests/test-module-test.js | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/ember-test-helpers/abstract-test-module.js b/lib/ember-test-helpers/abstract-test-module.js index ea271715c..5f093b70b 100644 --- a/lib/ember-test-helpers/abstract-test-module.js +++ b/lib/ember-test-helpers/abstract-test-module.js @@ -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; } }, @@ -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 diff --git a/tests/test-module-test.js b/tests/test-module-test.js index ce51aa07f..466f31dc6 100644 --- a/tests/test-module-test.js +++ b/tests/test-module-test.js @@ -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); @@ -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 "
foobar
"', function() { + expect(0); + document.getElementById('ember-testing').innerHTML = '
foobar
'; +}); + +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 "
foobar
"', function() { + expect(1); + equal(document.getElementById('ember-testing').innerHTML, '
foobar
'); + document.getElementById('ember-testing').innerHTML = ''; +});