Skip to content

Commit

Permalink
Reset internal test helper state for EmberDebug tests.
Browse files Browse the repository at this point in the history
Prior to this change we could not run any tests that leveraged the
`@ember/test-helpers` setup methods that ran _after_ the files in
`tests/ember_debug/**/*-test.js`. This was because the
`setupEIApp`/`destroyEIApp` helper functions would call `setApplication`
(to get a pristine state for their own tests), but would not clean up
after themselves (calling `setApplication` with the original value).

This change is a minimal patch to fix the fundamental issue (and adding
a single integration test to the mix to ensure it doesn't regress), but
a larger refactor is in order to simplify these setupEI/destroyEI test
helpers.
  • Loading branch information
rwjblue committed May 12, 2020
1 parent c9d8359 commit 08ef352
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/helpers/setup-destroy-ei-app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Application from '@ember/application';
import EmberRouter from '@ember/routing/router';
import {
getApplication,
setApplication,
setupApplicationContext,
setupContext,
Expand All @@ -10,7 +11,6 @@ import {
import { assert } from '@ember/debug';
import { run } from '@ember/runloop';


export async function setupEIApp(EmberDebug, routes) {
assert('setupEIApp requires `EmberDebug` to be passed.', EmberDebug !== undefined);

Expand All @@ -28,6 +28,7 @@ export async function setupEIApp(EmberDebug, routes) {
});
App.register('router:main', Router);

this._originalApp = getApplication();
await setApplication(App);
await setupContext(this);
await setupApplicationContext(this);
Expand All @@ -50,5 +51,8 @@ export async function destroyEIApp(EmberDebug, App) {
EmberDebug.destroyContainer();
await teardownApplicationContext(this);
await teardownContext(this);
return run(App, 'destroy');

run(App, 'destroy');

setApplication(this._originalApp);
}
14 changes: 14 additions & 0 deletions tests/integration/components/basic-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | basic', function(hooks) {
setupRenderingTest(hooks);

test('generally works', async function(assert) {
await render(hbs`Hello world!`);

assert.equal(this.element.textContent.trim(), 'Hello world!');
});
});

0 comments on commit 08ef352

Please sign in to comment.