Skip to content

Commit

Permalink
Test: Prefer config.destination and default `ember-basic-dropdown-w…
Browse files Browse the repository at this point in the history
…ormhole` (#946)

* Prefer config.destination and default 'ember-basic-dropdown-wormhole' over root element as destination in tests

Close #943

* Fix linting issues
  • Loading branch information
dagroe authored Feb 16, 2025
1 parent c8a4c67 commit 939f901
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion ember-basic-dropdown/src/components/basic-dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,28 @@ export default class BasicDropdown extends Component<BasicDropdownSignature> {
};

if (config.environment === 'test') {
// document doesn't exists in fastboot apps, for this reason we need this check
// document doesn't exist in fastboot apps, for this reason we need this check
if (typeof document === 'undefined') {
return 'ember-basic-dropdown-wormhole';
}

// check if destination exists in tests:
if (
config['ember-basic-dropdown'] &&
config['ember-basic-dropdown'].destination
) {
const destination = config['ember-basic-dropdown'].destination;
if (document.getElementById(destination) !== null) {
return destination;
}
}

// check if default element exists in tests:
if (document.getElementById('ember-basic-dropdown-wormhole') !== null) {
return 'ember-basic-dropdown-wormhole';
}

// fall back to rootElement as destination
const rootElement = config['APP']?.rootElement;
return (
document.querySelector(rootElement)?.id ??
Expand Down

0 comments on commit 939f901

Please sign in to comment.