Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit debcd6a

Browse files
committed
test: inject positioning root into test container if not available
1 parent a117aa9 commit debcd6a

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

addon/utils/get-root-element.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const RootID = 'ui-positioning-root';
88
* inserted by the addon and sits near the top of the DOM tree.
99
*/
1010
export default function getRootElement(context: unknown) {
11-
let root: HTMLElement | null = document.getElementById(RootID) || document.body;
11+
let root = document.getElementById(RootID);
1212

1313
runInDebug(() => {
1414
const config = getOwner(context)?.resolveRegistration<{ environment: string } | undefined>(
@@ -30,18 +30,27 @@ export default function getRootElement(context: unknown) {
3030
}
3131
}
3232

33-
root =
34-
(id
35-
? document.getElementById(id)
36-
: document.querySelector('#ember-testing > .ember-view')) ?? root;
33+
const testContainer = id
34+
? document.getElementById(id)
35+
: document.querySelector('#ember-testing > .ember-view');
36+
37+
if (testContainer) {
38+
if (!root) {
39+
root = document.createElement('div');
40+
root.id = RootID;
41+
}
42+
43+
testContainer.prepend(root);
44+
}
3745

3846
return;
3947
}
4048

41-
warn(`No destination element was found.`, !!root, {
49+
/* istanbul ignore next */
50+
warn(`No destination element was found, falling back to document.body.`, !!root, {
4251
id: '@nsf-open/ember-ui-foundation.no-destination-element',
4352
});
4453
});
4554

46-
return root;
55+
return root ?? document.body;
4756
}

tests/integration/components/ui-tooltip-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ module('Integration | Component | ui-tooltip', function (hooks) {
4949
</UiTooltip>
5050
`);
5151

52-
await triggerEvent('[data-test-id="tip"]', 'mouseenter');
53-
await triggerEvent('[data-test-id="tip"]', 'mouseleave');
52+
await triggerEvent('span[data-test-id="tip"]', 'mouseenter');
53+
await triggerEvent('span[data-test-id="tip"]', 'mouseleave');
5454

5555
assert.verifySteps(['onShow', 'onShown', 'onHide', 'onHidden']);
5656
});

0 commit comments

Comments
 (0)