Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mock-doc): add missing ShadowRoot window primitive #6011

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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