diff --git a/addon-test-support/@ember/test-helpers/dom/get-root-element.js b/addon-test-support/@ember/test-helpers/dom/get-root-element.js index 4bd67235b..a3aa8193a 100644 --- a/addon-test-support/@ember/test-helpers/dom/get-root-element.js +++ b/addon-test-support/@ember/test-helpers/dom/get-root-element.js @@ -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() { diff --git a/addon-test-support/@ember/test-helpers/index.js b/addon-test-support/@ember/test-helpers/index.js index 8e46f0dca..cd24bcb64 100644 --- a/addon-test-support/@ember/test-helpers/index.js +++ b/addon-test-support/@ember/test-helpers/index.js @@ -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'; diff --git a/tests/unit/dom/get-root-element-test.js b/tests/unit/dom/get-root-element-test.js new file mode 100644 index 000000000..9efda4fb1 --- /dev/null +++ b/tests/unit/dom/get-root-element-test.js @@ -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/); + }); +});