Skip to content

Commit

Permalink
Make getRootElement() public
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Demboski committed Jan 31, 2018
1 parent 3614dd0 commit 8cdd3bd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getContext } from '../setup-context';

/**
@private
Get the root element of the application under test (usually `#ember-testing`)
@public
@returns {Element} the root element
*/
export default function getRootElement() {
Expand Down
1 change: 1 addition & 0 deletions addon-test-support/@ember/test-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ export { default as triggerEvent } from './dom/trigger-event';
export { default as triggerKeyEvent } from './dom/trigger-key-event';
export { default as fillIn } from './dom/fill-in';
export { default as waitFor } from './dom/wait-for';
export { default as getRootElement } from './dom/get-root-element';
export { default as find } from './dom/find';
export { default as findAll } from './dom/find-all';
36 changes: 36 additions & 0 deletions tests/unit/dom/get-root-element-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { module, test } from 'qunit';
import { getRootElement, setupContext, teardownContext } from '@ember/test-helpers';
import hasEmberVersion from 'ember-test-helpers/has-ember-version';

module('DOM Helper: getRootElement', function(hooks) {
if (!hasEmberVersion(2, 4)) {
return;
}

let context;

hooks.beforeEach(function() {
context = {};
});

hooks.afterEach(async function() {
if (context.owner) {
await teardownContext(context);
}

document.getElementById('ember-testing').innerHTML = '';
});

test('works with context set', async function(assert) {
await setupContext(context);

let fixture = document.querySelector('#ember-testing');
assert.equal(getRootElement(), fixture);
});

test('throws without context set', function(assert) {
assert.throws(() => {
getRootElement();
}, /Must setup rendering context before attempting to interact with elements/);
});
});

0 comments on commit 8cdd3bd

Please sign in to comment.