Skip to content

Commit

Permalink
fix(mock-doc): add missing ShadowRoot window primitive (#6011)
Browse files Browse the repository at this point in the history
* fix(mock-doc): add missing ShadowRoot window primitive

* prettier
  • Loading branch information
christian-bromann authored Oct 4, 2024
1 parent 86a36b4 commit 2f944e2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function hydrateFactory($stencilWindow, $stencilHydrateOpts, $stencilHydr
var CSS = $stencilWindow.CSS;
var CustomEvent = $stencilWindow.CustomEvent;
var Document = $stencilWindow.Document;
var ShadowRoot = $stencilWindow.ShadowRoot;
var DocumentFragment = $stencilWindow.DocumentFragment;
var DocumentType = $stencilWindow.DocumentType;
var DOMTokenList = $stencilWindow.DOMTokenList;
Expand Down
62 changes: 62 additions & 0 deletions src/mock-doc/shadow-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { MockDocumentFragment } from './document-fragment';

export class MockShadowRoot extends MockDocumentFragment {
get activeElement(): HTMLElement | null {
return null;
}

set adoptedStyleSheets(_adoptedStyleSheets: StyleSheet[]) {
throw new Error('Unimplemented');
}

get adoptedStyleSheets(): StyleSheet[] {
return [];
}

get cloneable(): boolean {
return false;
}

get delegatesFocus(): boolean {
return false;
}

get fullscreenElement(): HTMLElement | null {
return null;
}

get host(): HTMLElement | null {
let parent = this.parentElement();
while (parent) {
if (parent.nodeType === 11) {
return parent;
}
parent = parent.parentElement();
}
return null;
}

get mode(): 'open' | 'closed' {
return 'open';
}

get pictureInPictureElement(): HTMLElement | null {
return null;
}

get pointerLockElement(): HTMLElement | null {
return null;
}

get serializable(): boolean {
return false;
}

get slotAssignment(): 'named' | 'manual' {
return 'named';
}

get styleSheets(): StyleSheet[] {
return [];
}
}
5 changes: 5 additions & 0 deletions src/mock-doc/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { MockNavigator } from './navigator';
import { MockElement, MockHTMLElement, MockNode, MockNodeList } from './node';
import { MockPerformance, resetPerformance } from './performance';
import { MockResizeObserver } from './resize-observer';
import { MockShadowRoot } from './shadow-root';
import { MockStorage } from './storage';

const nativeClearInterval = clearInterval;
Expand Down Expand Up @@ -188,6 +189,10 @@ export class MockWindow {
this.__docFragCstr = docFragCstr;
}

get ShadowRoot() {
return MockShadowRoot;
}

get DocumentType() {
if (this.__docTypeCstr == null) {
const ownerDocument = this.document;
Expand Down

0 comments on commit 2f944e2

Please sign in to comment.