mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-05 04:12:25 +00:00
Fix UploadModal DOM initialization for robust testing
Explicitly find the #uploadModal element within the parsed template wrapper using querySelector instead of relying on firstElementChild. This prevents null pointer exceptions in JSDOM environments where leading whitespace in the template string creates a text node as the first child. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
c3c8bd587d
commit
5420163135
1 file changed
+5
-5
@@ -160,11 +160,11 @@ export class UploadModal {
|
||||
wrapper.innerHTML = html;
|
||||
this.removeTrackingScripts(wrapper);
|
||||
|
||||
targetContainer.appendChild(wrapper.firstElementChild);
|
||||
this.root = targetContainer.querySelector("#uploadModal");
|
||||
if (!this.root && targetContainer.lastElementChild && targetContainer.lastElementChild.id === "uploadModal") {
|
||||
this.root = targetContainer.lastElementChild;
|
||||
}
|
||||
const modalRoot = wrapper.querySelector("#uploadModal");
|
||||
if (!modalRoot) throw new Error("UploadModal template must contain #uploadModal element");
|
||||
|
||||
targetContainer.appendChild(modalRoot);
|
||||
this.root = modalRoot;
|
||||
this.container = targetContainer;
|
||||
|
||||
this.cacheElements();
|
||||
|
||||
Reference in new issue
Block a user