@stencil/mock-doc 5.0.0-next.0 → 5.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # @stencil/mock-doc
2
+
3
+ A minimal mock DOM implementation for server-side rendering and unit testing of Stencil components.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install --save-dev @stencil/mock-doc
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### `createDocument(html?)` — lightweight document only
14
+
15
+ Use this when you only need a `Document` with no surrounding `window` object:
16
+
17
+ ```ts
18
+ import { createDocument, serializeNodeToHtml } from '@stencil/mock-doc';
19
+
20
+ const doc = createDocument('<div class="greeting">Hello</div>');
21
+ const el = doc.querySelector('.greeting');
22
+ el.textContent = 'Hello, world!';
23
+
24
+ console.log(serializeNodeToHtml(el, { outerHtml: true }));
25
+ // <div class="greeting">Hello, world!</div>
26
+ ```
27
+
28
+ ### `MockWindow(html?)` — full window environment
29
+
30
+ Use this when your code accesses `window`, `location`, `navigator`, `localStorage`, etc.:
31
+
32
+ ```ts
33
+ import { MockWindow, serializeNodeToHtml } from '@stencil/mock-doc';
34
+
35
+ const win = new MockWindow('<html><body><my-comp></my-comp></body></html>');
36
+ const doc = win.document;
37
+
38
+ const el = doc.querySelector('my-comp');
39
+ el.setAttribute('label', 'Hello');
40
+
41
+ const html = serializeNodeToHtml(doc);
42
+ ```
43
+
44
+ ### `parseHtmlToDocument` / `parseHtmlToFragment`
45
+
46
+ Parse an HTML string into a `Document` or a `DocumentFragment`:
47
+
48
+ ```ts
49
+ import { parseHtmlToDocument, parseHtmlToFragment } from '@stencil/mock-doc';
50
+
51
+ const doc = parseHtmlToDocument('<p>Hello</p>');
52
+ const frag = parseHtmlToFragment('<li>one</li><li>two</li>');
53
+ ```
54
+
55
+ ### `serializeNodeToHtml(node, options?)`
56
+
57
+ Serialize any node back to an HTML string. Useful for snapshot tests and SSR output.
58
+
59
+ ```ts
60
+ import { serializeNodeToHtml } from '@stencil/mock-doc';
61
+
62
+ // Pretty-printed output
63
+ const pretty = serializeNodeToHtml(doc, { prettyHtml: true });
64
+
65
+ // Outer HTML of a single element (includes the element's own tag)
66
+ const outer = serializeNodeToHtml(el, { outerHtml: true });
67
+
68
+ // Serialize shadow roots as Declarative Shadow DOM
69
+ const dsd = serializeNodeToHtml(doc, {
70
+ serializeShadowRoot: 'declarative-shadow-dom',
71
+ });
72
+ ```
73
+
74
+ Key options:
75
+
76
+ | Option | Default | Description |
77
+ |---|---|---|
78
+ | `prettyHtml` | `false` | Indent and add newlines |
79
+ | `indentSpaces` | `2` (when pretty) | Spaces per indent level |
80
+ | `outerHtml` | `false` | Include the root element's own tag |
81
+ | `removeEmptyAttributes` | `true` | Strip attributes with empty string values |
82
+ | `removeHtmlComments` | `false` | Strip HTML comments |
83
+ | `serializeShadowRoot` | — | `'declarative-shadow-dom'` or `'scoped'` |
84
+ | `fullDocument` | `false` | Always emit a full `<!DOCTYPE html>` document |
85
+
86
+ ### `setupGlobal` / `teardownGlobal` — test framework integration
87
+
88
+ Installs a `MockWindow` onto `global` so that `window`, `document`, `customElements`, etc. are available without a browser. Call in `beforeEach`/`afterEach` to get a fresh environment per test:
89
+
90
+ ```ts
91
+ import { setupGlobal, teardownGlobal } from '@stencil/mock-doc';
92
+
93
+ beforeEach(() => setupGlobal(global));
94
+ afterEach(() => teardownGlobal(global));
95
+
96
+ it('reads document.title', () => {
97
+ document.title = 'My Page';
98
+ expect(document.title).toBe('My Page');
99
+ });
100
+ ```
101
+
102
+ `setupGlobal` returns the `MockWindow` it created, which you can use to reach `window`-level APIs directly if needed.
103
+
104
+ ### `patchWindow(win)` — fill gaps in a partial window
105
+
106
+ Useful when running in an environment that has _some_ browser globals but is missing others (e.g. a custom SSR runtime):
107
+
108
+ ```ts
109
+ import { patchWindow } from '@stencil/mock-doc';
110
+
111
+ patchWindow(globalThis); // fills in any missing window APIs with mock implementations
112
+ ```
113
+
114
+ ### Fetch mocks
115
+
116
+ Use `MockRequest`, `MockResponse`, and `MockHeaders` to test code that calls `fetch` without hitting the network:
117
+
118
+ ```ts
119
+ import { MockRequest, MockResponse, MockHeaders } from '@stencil/mock-doc';
120
+
121
+ // Simulate an incoming request
122
+ const req = new MockRequest('/api/data', { method: 'POST' });
123
+ console.log(req.method); // 'POST'
124
+ console.log(req.url); // 'http://localhost/api/data'
125
+
126
+ // Build a response your handler returns
127
+ const res = new MockResponse(JSON.stringify({ ok: true }), {
128
+ status: 200,
129
+ headers: new MockHeaders({ 'content-type': 'application/json' }),
130
+ });
131
+
132
+ const body = await res.json(); // { ok: true }
133
+ ```
package/dist/index.d.mts CHANGED
@@ -63,7 +63,7 @@ declare class MockCSSRule {
63
63
  declare class MockCSSStyleSheet {
64
64
  ownerNode?: MockStyleElement;
65
65
  type: string;
66
- parentStyleSheet: MockCSSStyleSheet;
66
+ parentStyleSheet: MockCSSStyleSheet | null;
67
67
  cssRules: MockCSSRule[];
68
68
  constructor(ownerNode?: MockStyleElement);
69
69
  get rules(): MockCSSRule[];
@@ -117,7 +117,6 @@ declare class MockHistory {
117
117
  //#endregion
118
118
  //#region src/intersection-observer.d.ts
119
119
  declare class MockIntersectionObserver {
120
- constructor();
121
120
  disconnect(): void;
122
121
  observe(): void;
123
122
  takeRecords(): any[];
@@ -140,6 +139,7 @@ declare class MockLocation implements Location {
140
139
  private _href;
141
140
  get href(): string;
142
141
  set href(value: string);
142
+ constructor();
143
143
  assign(_url: string): void;
144
144
  reload(_forcedReload?: boolean): void;
145
145
  replace(_url: string): void;
@@ -157,7 +157,6 @@ declare class MockNavigator {
157
157
  //#endregion
158
158
  //#region src/resize-observer.d.ts
159
159
  declare class MockResizeObserver {
160
- constructor();
161
160
  disconnect(): void;
162
161
  observe(): void;
163
162
  takeRecords(): any[];
@@ -166,15 +165,26 @@ declare class MockResizeObserver {
166
165
  //#endregion
167
166
  //#region src/shadow-root.d.ts
168
167
  declare class MockShadowRoot extends MockDocumentFragment {
168
+ private _mode;
169
+ private _delegatesFocus;
170
+ private _clonable;
171
+ private _serializable;
172
+ private _referenceTarget;
169
173
  get activeElement(): HTMLElement | null;
170
- get cloneable(): boolean;
174
+ get clonable(): boolean;
175
+ set clonable(value: boolean);
171
176
  get delegatesFocus(): boolean;
177
+ set delegatesFocus(value: boolean);
172
178
  get fullscreenElement(): HTMLElement | null;
173
179
  get host(): HTMLElement | null;
174
180
  get mode(): 'open' | 'closed';
181
+ set mode(value: 'open' | 'closed');
175
182
  get pictureInPictureElement(): HTMLElement | null;
176
183
  get pointerLockElement(): HTMLElement | null;
184
+ get referenceTarget(): string | null;
185
+ set referenceTarget(value: string | null);
177
186
  get serializable(): boolean;
187
+ set serializable(value: boolean);
178
188
  get slotAssignment(): 'named' | 'manual';
179
189
  get styleSheets(): StyleSheet[];
180
190
  }
@@ -217,7 +227,7 @@ declare class MockWindow {
217
227
  __allowInterval: boolean;
218
228
  URL: typeof URL;
219
229
  console: Console;
220
- customElements: CustomElementRegistry;
230
+ customElements: CustomElementRegistry | null;
221
231
  document: Document;
222
232
  performance: Performance;
223
233
  devicePixelRatio: number;
@@ -239,7 +249,7 @@ declare class MockWindow {
239
249
  KeyboardEvent: typeof MockKeyboardEvent;
240
250
  MouseEvent: typeof MockMouseEvent;
241
251
  constructor(html?: string | boolean);
242
- addEventListener(type: string, handler: (ev?: any) => void): void;
252
+ addEventListener(type: string, handler: (ev?: any) => void, options?: boolean | AddEventListenerOptions): void;
243
253
  alert(msg: string): void;
244
254
  blur(): any;
245
255
  cancelAnimationFrame(id: any): void;
@@ -264,6 +274,35 @@ declare class MockWindow {
264
274
  set DOMTokenList(domTokenListCstr: any);
265
275
  dispatchEvent(ev: MockEvent): boolean;
266
276
  get Element(): typeof MockElement;
277
+ get DOMException(): {
278
+ new (message?: string, name?: string): DOMException;
279
+ prototype: DOMException;
280
+ readonly INDEX_SIZE_ERR: 1;
281
+ readonly DOMSTRING_SIZE_ERR: 2;
282
+ readonly HIERARCHY_REQUEST_ERR: 3;
283
+ readonly WRONG_DOCUMENT_ERR: 4;
284
+ readonly INVALID_CHARACTER_ERR: 5;
285
+ readonly NO_DATA_ALLOWED_ERR: 6;
286
+ readonly NO_MODIFICATION_ALLOWED_ERR: 7;
287
+ readonly NOT_FOUND_ERR: 8;
288
+ readonly NOT_SUPPORTED_ERR: 9;
289
+ readonly INUSE_ATTRIBUTE_ERR: 10;
290
+ readonly INVALID_STATE_ERR: 11;
291
+ readonly SYNTAX_ERR: 12;
292
+ readonly INVALID_MODIFICATION_ERR: 13;
293
+ readonly NAMESPACE_ERR: 14;
294
+ readonly INVALID_ACCESS_ERR: 15;
295
+ readonly VALIDATION_ERR: 16;
296
+ readonly TYPE_MISMATCH_ERR: 17;
297
+ readonly SECURITY_ERR: 18;
298
+ readonly NETWORK_ERR: 19;
299
+ readonly ABORT_ERR: 20;
300
+ readonly URL_MISMATCH_ERR: 21;
301
+ readonly QUOTA_EXCEEDED_ERR: 22;
302
+ readonly TIMEOUT_ERR: 23;
303
+ readonly INVALID_NODE_TYPE_ERR: 24;
304
+ readonly DATA_CLONE_ERR: 25;
305
+ };
267
306
  fetch(input: any, init?: any): any;
268
307
  focus(): any;
269
308
  getComputedStyle(_: any): any;
@@ -297,7 +336,7 @@ declare class MockWindow {
297
336
  prompt(): string;
298
337
  open(): any;
299
338
  get origin(): string;
300
- removeEventListener(type: string, handler: any): void;
339
+ removeEventListener(type: string, handler: any, options?: boolean | EventListenerOptions): void;
301
340
  requestAnimationFrame(callback: (timestamp: number) => void): number;
302
341
  requestIdleCallback(callback: (deadline: {
303
342
  didTimeout: boolean;
@@ -402,7 +441,7 @@ declare class MockWindow {
402
441
  onwebkitfullscreenerror(): void;
403
442
  onwheel(): void;
404
443
  }
405
- declare function cloneWindow(srcWin: Window, opts?: {
444
+ declare function cloneWindow(srcWin: Window | MockWindow, opts?: {
406
445
  customElementProxy?: boolean;
407
446
  }): MockWindow | null;
408
447
  declare function cloneDocument(srcDoc: Document): Document;
@@ -411,7 +450,19 @@ declare function cloneDocument(srcDoc: Document): Document;
411
450
  * only allow setInterval() to fire once, also constrained to 1ms.
412
451
  * @param win the mock window instance to update
413
452
  */
414
- declare function constrainTimeouts(win: any): void;
453
+ declare function constrainTimeouts(win: MockWindow): void;
454
+ /**
455
+ * Reset a window so the same object can be used for another render, then parse `html` into its
456
+ * document.
457
+ *
458
+ * Code that captured the window's sub-objects (e.g. an SSR platform holding `win.location`,
459
+ * `win.console` or `win.document`) keeps working: those objects are kept and reset in place,
460
+ * rather than replaced. Everything else on the window - including anything a previous render
461
+ * added - is removed.
462
+ * @param win the window to reset
463
+ * @param html the HTML for the next render
464
+ */
465
+ declare function resetWindowForReuse(win: MockWindow, html: string): void;
415
466
  //#endregion
416
467
  //#region src/event.d.ts
417
468
  declare class MockEvent {
@@ -419,10 +470,10 @@ declare class MockEvent {
419
470
  cancelBubble: boolean;
420
471
  cancelable: boolean;
421
472
  composed: boolean;
422
- currentTarget: MockElement;
473
+ currentTarget: MockElement | null;
423
474
  defaultPrevented: boolean;
424
- srcElement: MockElement;
425
- target: MockElement;
475
+ srcElement: MockElement | null;
476
+ target: MockElement | null;
426
477
  timeStamp: number;
427
478
  type: string;
428
479
  constructor(type: string, eventInitDict?: EventInit);
@@ -430,7 +481,8 @@ declare class MockEvent {
430
481
  stopPropagation(): void;
431
482
  stopImmediatePropagation(): void;
432
483
  /**
433
- * @ref https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath
484
+ * Get the composed path of event propagation.
485
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath
434
486
  * @returns a composed path of the event
435
487
  */
436
488
  composedPath(): MockElement[];
@@ -461,7 +513,7 @@ declare class MockMouseEvent extends MockEvent {
461
513
  metaKey: boolean;
462
514
  button: number;
463
515
  buttons: number;
464
- relatedTarget: EventTarget;
516
+ relatedTarget: EventTarget | null;
465
517
  constructor(type: string, mouseEventInitDic?: MouseEventInit);
466
518
  }
467
519
  declare class MockUIEvent extends MockEvent {
@@ -476,7 +528,9 @@ declare class MockFocusEvent extends MockUIEvent {
476
528
  declare class MockEventListener {
477
529
  type: string;
478
530
  handler: (ev?: any) => void;
479
- constructor(type: string, handler: any);
531
+ capture: boolean;
532
+ once: boolean;
533
+ constructor(type: string, handler: any, options?: boolean | AddEventListenerOptions);
480
534
  }
481
535
  interface EventTarget {
482
536
  __listeners: MockEventListener[];
@@ -528,7 +582,7 @@ declare class MockTokenList {
528
582
  add(...tokens: string[]): void;
529
583
  remove(...tokens: string[]): void;
530
584
  contains(token: string): boolean;
531
- toggle(token: string): void;
585
+ toggle(token: string, force?: boolean): boolean;
532
586
  get length(): number;
533
587
  item(index: number): string;
534
588
  toString(): string;
@@ -549,9 +603,9 @@ declare class MockNode {
549
603
  append(...items: (MockNode | string)[]): void;
550
604
  prepend(...items: (MockNode | string)[]): void;
551
605
  cloneNode(deep?: boolean): MockNode;
552
- compareDocumentPosition(_other: MockNode): number;
606
+ compareDocumentPosition(other: MockNode): number;
553
607
  get firstChild(): MockNode | null;
554
- insertBefore(newNode: MockNode, referenceNode: MockNode): MockNode;
608
+ insertBefore(newNode: MockNode, referenceNode: MockNode | null): MockNode;
555
609
  get isConnected(): boolean;
556
610
  isSameNode(node: any): boolean;
557
611
  get lastChild(): MockNode | null;
@@ -567,8 +621,8 @@ declare class MockNode {
567
621
  replaceChild(newChild: MockNode, oldChild: MockNode): MockNode;
568
622
  get textContent(): string;
569
623
  set textContent(value: string);
570
- addEventListener(type: string, handler: (ev?: any) => void): void;
571
- removeEventListener(type: string, handler: any): void;
624
+ addEventListener(type: string, handler: (ev?: any) => void, options?: boolean | AddEventListenerOptions): void;
625
+ removeEventListener(type: string, handler: any, options?: boolean | EventListenerOptions): void;
572
626
  dispatchEvent(ev: MockEvent): boolean;
573
627
  static ELEMENT_NODE: number;
574
628
  static TEXT_NODE: number;
@@ -578,7 +632,17 @@ declare class MockNode {
578
632
  static DOCUMENT_TYPE_NODE: number;
579
633
  static DOCUMENT_FRAGMENT_NODE: number;
580
634
  }
581
- type MockElementInternals = Record<keyof ElementInternals, null>;
635
+ /**
636
+ * Just enough of `ElementInternals` for form-associated components to run without throwing.
637
+ * There is no form, validation or accessibility tree to update, so the methods do nothing.
638
+ */
639
+ declare class MockElementInternals {
640
+ states: Set<string>;
641
+ setFormValue(): void;
642
+ setValidity(): void;
643
+ checkValidity(): boolean;
644
+ reportValidity(): boolean;
645
+ }
582
646
  declare class MockElement extends MockNode {
583
647
  __namespaceURI: string | null;
584
648
  __localName: string | null;
@@ -587,8 +651,10 @@ declare class MockElement extends MockNode {
587
651
  __style: MockCSSStyleDeclaration | null | undefined;
588
652
  attachInternals(): MockElementInternals;
589
653
  constructor(ownerDocument: any, nodeName: string | null, namespaceURI?: string | null);
590
- addEventListener(type: string, handler: (ev?: any) => void): void;
591
- attachShadow(_opts: ShadowRootInit): any;
654
+ addEventListener(type: string, handler: (ev?: any) => void, options?: boolean | AddEventListenerOptions): void;
655
+ attachShadow(_opts: ShadowRootInit & {
656
+ referenceTarget?: string;
657
+ }): any;
592
658
  blur(): void;
593
659
  get localName(): string;
594
660
  get namespaceURI(): string;
@@ -609,7 +675,9 @@ declare class MockElement extends MockNode {
609
675
  set part(value: string | MockTokenList);
610
676
  click(): void;
611
677
  cloneNode(_deep?: boolean): MockElement;
612
- closest(selector: string): this;
678
+ closest<K extends keyof HTMLElementTagNameMap>(selector: K): HTMLElementTagNameMap[K] | null;
679
+ closest<K extends keyof SVGElementTagNameMap>(selector: K): SVGElementTagNameMap[K] | null;
680
+ closest<E extends Element = Element>(selector: string): E | null;
613
681
  get dataset(): any;
614
682
  get dir(): string;
615
683
  set dir(value: string);
@@ -650,8 +718,8 @@ declare class MockElement extends MockNode {
650
718
  insertAdjacentText(position: 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend', text: string): void;
651
719
  hasAttribute(attrName: string): boolean;
652
720
  hasAttributeNS(namespaceURI: string | null, name: string): boolean;
653
- get hidden(): boolean;
654
- set hidden(isHidden: boolean);
721
+ get hidden(): boolean | "until-found";
722
+ set hidden(isHidden: boolean | 'until-found');
655
723
  get lang(): string;
656
724
  set lang(value: string);
657
725
  get lastElementChild(): MockElement | null;
@@ -661,11 +729,15 @@ declare class MockElement extends MockNode {
661
729
  get previousElementSibling(): any;
662
730
  getElementsByClassName(classNames: string): MockElement[];
663
731
  getElementsByTagName(tagName: string): MockElement[];
664
- querySelector(selector: string): any;
665
- querySelectorAll(selector: string): any;
732
+ querySelector<K extends keyof HTMLElementTagNameMap>(selectors: K | `${K}.${string}` | `${K}#${string}` | `${K}[${string}` | `${K}:${string}`): HTMLElementTagNameMap[K] | null;
733
+ querySelector<K extends keyof SVGElementTagNameMap>(selectors: K | `${K}.${string}` | `${K}#${string}` | `${K}[${string}` | `${K}:${string}`): SVGElementTagNameMap[K] | null;
734
+ querySelector<E extends Element = Element>(selectors: string): E | null;
735
+ querySelectorAll<K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K][];
736
+ querySelectorAll<K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K][];
737
+ querySelectorAll<E extends Element = Element>(selectors: string): E[];
666
738
  removeAttribute(attrName: string): void;
667
739
  removeAttributeNS(namespaceURI: string | null, attrName: string): void;
668
- removeEventListener(type: string, handler: any): void;
740
+ removeEventListener(type: string, handler: any, options?: boolean | EventListenerOptions): void;
669
741
  setAttribute(attrName: string, value: any): void;
670
742
  setAttributeNS(namespaceURI: string | null, attrName: string, value: any): void;
671
743
  get style(): any;
@@ -809,17 +881,11 @@ declare class MockComment extends MockNode {
809
881
  //#region src/constants.d.ts
810
882
  declare const enum NODE_TYPES {
811
883
  ELEMENT_NODE = 1,
812
- ATTRIBUTE_NODE = 2,
813
884
  TEXT_NODE = 3,
814
- CDATA_SECTION_NODE = 4,
815
- ENTITY_REFERENCE_NODE = 5,
816
- ENTITY_NODE = 6,
817
- PROCESSING_INSTRUCTION_NODE = 7,
818
885
  COMMENT_NODE = 8,
819
886
  DOCUMENT_NODE = 9,
820
887
  DOCUMENT_TYPE_NODE = 10,
821
- DOCUMENT_FRAGMENT_NODE = 11,
822
- NOTATION_NODE = 12
888
+ DOCUMENT_FRAGMENT_NODE = 11
823
889
  }
824
890
  //#endregion
825
891
  //#region src/document-type-node.d.ts
@@ -828,11 +894,47 @@ declare class MockDocumentTypeNode extends MockHTMLElement {
828
894
  }
829
895
  //#endregion
830
896
  //#region src/document.d.ts
897
+ /**
898
+ * Interface for nwsapi instance methods we use.
899
+ */
900
+ interface NwsapiInstance {
901
+ configure(config: {
902
+ LOGERRORS?: boolean;
903
+ VERBOSITY?: boolean;
904
+ IDS_DUPES?: boolean;
905
+ }): void;
906
+ match(selector: string, element: unknown): boolean;
907
+ first(selector: string, context: unknown): unknown | null;
908
+ select(selector: string, context: unknown): unknown[];
909
+ closest(selector: string, element: unknown): unknown | null;
910
+ }
831
911
  declare class MockDocument extends MockHTMLElement {
912
+ #private;
832
913
  defaultView: any;
833
914
  cookie: string;
834
915
  referrer: string;
916
+ /**
917
+ * Returns 'CSS1Compat' for standards mode (the default).
918
+ * Required by nwsapi for quirks mode detection.
919
+ */
920
+ readonly compatMode = "CSS1Compat";
921
+ /**
922
+ * Returns the MIME type of the document.
923
+ * Required by nwsapi for HTML document detection.
924
+ */
925
+ readonly contentType = "text/html";
835
926
  constructor(html?: string | boolean | null, win?: any);
927
+ /**
928
+ * Get the nwsapi instance for this document.
929
+ * Lazily creates one if it doesn't exist.
930
+ * Creates a window if the document doesn't have one.
931
+ * @returns the nwsapi instance
932
+ */
933
+ _getDOMSelector(): NwsapiInstance;
934
+ /**
935
+ * Clear the nwsapi cache. Call this when the document structure changes significantly.
936
+ */
937
+ _clearDOMSelector(): void;
836
938
  get dir(): string;
837
939
  set dir(value: string);
838
940
  get localName(): never;
@@ -840,17 +942,17 @@ declare class MockDocument extends MockHTMLElement {
840
942
  set location(val: string);
841
943
  get baseURI(): string;
842
944
  get URL(): string;
843
- get styleSheets(): any;
844
- get scripts(): any;
845
- get forms(): any;
846
- get images(): any;
847
- get scrollingElement(): MockElement | MockHTMLElement;
848
- get documentElement(): MockElement | MockHTMLElement;
849
- set documentElement(documentElement: MockElement | MockHTMLElement);
850
- get head(): MockElement | MockHTMLElement;
851
- set head(head: MockElement | MockHTMLElement);
852
- get body(): MockElement | MockHTMLElement;
853
- set body(body: MockElement | MockHTMLElement);
945
+ get styleSheets(): HTMLStyleElement[];
946
+ get scripts(): HTMLScriptElement[];
947
+ get forms(): HTMLFormElement[];
948
+ get images(): HTMLImageElement[];
949
+ get scrollingElement(): MockHTMLElement | MockElement;
950
+ get documentElement(): MockHTMLElement | MockElement;
951
+ set documentElement(documentElement: MockHTMLElement | MockElement);
952
+ get head(): MockHTMLElement | MockElement;
953
+ set head(head: MockHTMLElement | MockElement);
954
+ get body(): MockHTMLElement | MockElement;
955
+ set body(body: MockHTMLElement | MockElement);
854
956
  appendChild(newNode: MockElement): MockElement;
855
957
  createComment(data: string): MockComment;
856
958
  createAttribute(attrName: string): MockAttr;
@@ -860,12 +962,21 @@ declare class MockDocument extends MockHTMLElement {
860
962
  createTextNode(text: string): MockTextNode;
861
963
  createDocumentFragment(): MockDocumentFragment;
862
964
  createDocumentTypeNode(): MockDocumentTypeNode;
965
+ /**
966
+ * Creates a TreeWalker for traversing the document tree.
967
+ * This is a simplified implementation for dom-selector compatibility.
968
+ * @param root - the root node for the tree walker
969
+ * @param whatToShow - a bitmask specifying which nodes to show
970
+ * @param filter - an optional node filter
971
+ * @returns a new TreeWalker instance
972
+ */
973
+ createTreeWalker(root: MockElement, whatToShow?: number, filter?: NodeFilter | null): TreeWalker;
863
974
  getElementById(id: string): MockElement;
864
975
  getElementsByName(elmName: string): MockElement[];
865
976
  get title(): string;
866
977
  set title(value: string);
867
978
  }
868
- declare function createDocument(html?: string | boolean): Document;
979
+ declare function createDocument(html?: string | boolean | null): Document;
869
980
  declare function createFragment(html?: string): DocumentFragment;
870
981
  declare function resetDocument(doc: Document): void;
871
982
  //#endregion
@@ -889,7 +1000,7 @@ declare class MockHeaders {
889
1000
  value: string;
890
1001
  done: boolean;
891
1002
  };
892
- [Symbol.iterator](): any;
1003
+ [Symbol.iterator](): /*elided*/ any;
893
1004
  };
894
1005
  set(key: string, value: string): void;
895
1006
  values(): any;
@@ -897,8 +1008,8 @@ declare class MockHeaders {
897
1008
  }
898
1009
  //#endregion
899
1010
  //#region src/parse-html.d.ts
900
- declare function parseHtmlToDocument(html: string, ownerDocument?: MockDocument): any;
901
- declare function parseHtmlToFragment(html: string, ownerDocument?: MockDocument): any;
1011
+ declare function parseHtmlToDocument(html: string, ownerDocument?: MockDocument | null): any;
1012
+ declare function parseHtmlToFragment(html: string, ownerDocument?: MockDocument | null): any;
902
1013
  //#endregion
903
1014
  //#region src/request-response.d.ts
904
1015
  type MockRequestInfo = MockRequest | string;
@@ -957,4 +1068,4 @@ declare class MockResponse {
957
1068
  clone(): MockResponse;
958
1069
  }
959
1070
  //#endregion
960
- export { MockAttr, MockAttributeMap, MockComment, MockCustomEvent, MockDocument, MockElement, MockHTMLElement, MockHeaders, MockKeyboardEvent, MockMouseEvent, MockNode, MockRequest, type MockRequestInfo, type MockRequestInit, MockResponse, type MockResponseInit, MockTextNode, MockWindow, NODE_TYPES, type SerializeNodeToHtmlOptions, cloneAttributes, cloneDocument, cloneWindow, constrainTimeouts, createDocument, createFragment, parseHtmlToDocument, parseHtmlToFragment, patchWindow, resetDocument, serializeNodeToHtml, setupGlobal, teardownGlobal };
1071
+ export { MockAttr, MockAttributeMap, MockComment, MockCustomEvent, MockDocument, MockElement, MockHTMLElement, MockHeaders, MockKeyboardEvent, MockMouseEvent, MockNode, MockRequest, type MockRequestInfo, type MockRequestInit, MockResponse, type MockResponseInit, MockTextNode, MockWindow, NODE_TYPES, type SerializeNodeToHtmlOptions, cloneAttributes, cloneDocument, cloneWindow, constrainTimeouts, createDocument, createFragment, parseHtmlToDocument, parseHtmlToFragment, patchWindow, resetDocument, resetWindowForReuse, serializeNodeToHtml, setupGlobal, teardownGlobal };