@remote-dom/polyfill 1.5.1 → 1.6.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/CHANGELOG.md +88 -0
- package/README.md +51 -3
- package/build/cjs/Attr.cjs +33 -4
- package/build/cjs/CharacterData.cjs +10 -0
- package/build/cjs/ChildNode.cjs +79 -13
- package/build/cjs/Comment.cjs +1 -1
- package/build/cjs/CustomElementRegistry.cjs +27 -2
- package/build/cjs/CustomEvent.cjs +2 -2
- package/build/cjs/Document.cjs +56 -32
- package/build/cjs/DocumentFragment.cjs +6 -2
- package/build/cjs/Element.cjs +68 -8
- package/build/cjs/Event.cjs +29 -27
- package/build/cjs/EventTarget.cjs +128 -58
- package/build/cjs/HTMLTemplateElement.cjs +1 -0
- package/build/cjs/MutationObserver.cjs +167 -1
- package/build/cjs/NamedNodeMap.cjs +82 -45
- package/build/cjs/Node.cjs +47 -11
- package/build/cjs/NodeList.cjs +9 -1
- package/build/cjs/ParentNode.cjs +319 -77
- package/build/cjs/SVGElement.cjs +1 -1
- package/build/cjs/Text.cjs +1 -1
- package/build/cjs/Window.cjs +131 -38
- package/build/cjs/attribute-reactions.cjs +20 -0
- package/build/cjs/constants.cjs +48 -24
- package/build/cjs/custom-element-reactions.cjs +52 -0
- package/build/cjs/dom-exception.cjs +15 -0
- package/build/cjs/hook-effects.cjs +51 -0
- package/build/cjs/names.cjs +61 -0
- package/build/cjs/selectors.cjs +213 -122
- package/build/cjs/serialization.cjs +168 -65
- package/build/cjs/shared.cjs +177 -28
- package/build/esm/Attr.mjs +34 -5
- package/build/esm/CharacterData.mjs +10 -0
- package/build/esm/ChildNode.mjs +76 -15
- package/build/esm/Comment.mjs +2 -2
- package/build/esm/CustomElementRegistry.mjs +27 -2
- package/build/esm/CustomEvent.mjs +2 -2
- package/build/esm/Document.mjs +60 -35
- package/build/esm/DocumentFragment.mjs +7 -3
- package/build/esm/Element.mjs +69 -9
- package/build/esm/Event.mjs +27 -27
- package/build/esm/EventTarget.mjs +130 -60
- package/build/esm/HTMLTemplateElement.mjs +2 -1
- package/build/esm/MutationObserver.mjs +166 -2
- package/build/esm/NamedNodeMap.mjs +83 -46
- package/build/esm/Node.mjs +48 -12
- package/build/esm/NodeList.mjs +9 -1
- package/build/esm/ParentNode.mjs +322 -81
- package/build/esm/SVGElement.mjs +2 -2
- package/build/esm/Text.mjs +2 -2
- package/build/esm/Window.mjs +132 -39
- package/build/esm/attribute-reactions.mjs +16 -0
- package/build/esm/constants.mjs +28 -23
- package/build/esm/custom-element-reactions.mjs +47 -0
- package/build/esm/dom-exception.mjs +11 -0
- package/build/esm/hook-effects.mjs +46 -0
- package/build/esm/names.mjs +54 -0
- package/build/esm/selectors.mjs +202 -124
- package/build/esm/serialization.mjs +169 -66
- package/build/esm/shared.mjs +173 -30
- package/build/esnext/Attr.esnext +45 -5
- package/build/esnext/CharacterData.esnext +10 -0
- package/build/esnext/ChildNode.esnext +84 -15
- package/build/esnext/Comment.esnext +2 -2
- package/build/esnext/CustomElementRegistry.esnext +42 -0
- package/build/esnext/CustomEvent.esnext +2 -2
- package/build/esnext/Document.esnext +69 -32
- package/build/esnext/DocumentFragment.esnext +6 -2
- package/build/esnext/Element.esnext +78 -9
- package/build/esnext/Event.esnext +36 -37
- package/build/esnext/EventTarget.esnext +133 -61
- package/build/esnext/HTMLTemplateElement.esnext +3 -1
- package/build/esnext/MutationObserver.esnext +163 -2
- package/build/esnext/NamedNodeMap.esnext +110 -42
- package/build/esnext/Node.esnext +50 -12
- package/build/esnext/NodeList.esnext +1 -1
- package/build/esnext/ParentNode.esnext +352 -79
- package/build/esnext/SVGElement.esnext +2 -2
- package/build/esnext/Text.esnext +2 -2
- package/build/esnext/Window.esnext +120 -16
- package/build/esnext/attribute-reactions.esnext +21 -0
- package/build/esnext/constants.esnext +34 -21
- package/build/esnext/custom-element-reactions.esnext +49 -0
- package/build/esnext/dom-exception.esnext +11 -0
- package/build/esnext/hook-effects.esnext +46 -0
- package/build/esnext/names.esnext +61 -0
- package/build/esnext/selectors.esnext +202 -100
- package/build/esnext/serialization.esnext +171 -48
- package/build/esnext/shared.esnext +181 -34
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/Attr.d.ts +6 -4
- package/build/typescript/Attr.d.ts.map +1 -1
- package/build/typescript/CharacterData.d.ts.map +1 -1
- package/build/typescript/ChildNode.d.ts +5 -0
- package/build/typescript/ChildNode.d.ts.map +1 -1
- package/build/typescript/ClipboardEvent.d.ts.map +1 -1
- package/build/typescript/Comment.d.ts +2 -2
- package/build/typescript/Comment.d.ts.map +1 -1
- package/build/typescript/CustomElementRegistry.d.ts +1 -0
- package/build/typescript/CustomElementRegistry.d.ts.map +1 -1
- package/build/typescript/CustomEvent.d.ts.map +1 -1
- package/build/typescript/Document.d.ts +10 -5
- package/build/typescript/Document.d.ts.map +1 -1
- package/build/typescript/DocumentFragment.d.ts +2 -1
- package/build/typescript/DocumentFragment.d.ts.map +1 -1
- package/build/typescript/Element.d.ts +16 -7
- package/build/typescript/Element.d.ts.map +1 -1
- package/build/typescript/ErrorEvent.d.ts.map +1 -1
- package/build/typescript/Event.d.ts +9 -10
- package/build/typescript/Event.d.ts.map +1 -1
- package/build/typescript/EventTarget.d.ts +20 -3
- package/build/typescript/EventTarget.d.ts.map +1 -1
- package/build/typescript/FocusEvent.d.ts.map +1 -1
- package/build/typescript/HTMLTemplateElement.d.ts.map +1 -1
- package/build/typescript/MutationObserver.d.ts +42 -0
- package/build/typescript/MutationObserver.d.ts.map +1 -1
- package/build/typescript/NamedNodeMap.d.ts +5 -3
- package/build/typescript/NamedNodeMap.d.ts.map +1 -1
- package/build/typescript/Node.d.ts +4 -3
- package/build/typescript/Node.d.ts.map +1 -1
- package/build/typescript/NodeList.d.ts +3 -2
- package/build/typescript/NodeList.d.ts.map +1 -1
- package/build/typescript/ParentNode.d.ts +29 -10
- package/build/typescript/ParentNode.d.ts.map +1 -1
- package/build/typescript/PromiseRejectionEvent.d.ts.map +1 -1
- package/build/typescript/SVGElement.d.ts +1 -1
- package/build/typescript/SVGElement.d.ts.map +1 -1
- package/build/typescript/Text.d.ts +1 -1
- package/build/typescript/Text.d.ts.map +1 -1
- package/build/typescript/ToggleEvent.d.ts.map +1 -1
- package/build/typescript/Window.d.ts +5 -1
- package/build/typescript/Window.d.ts.map +1 -1
- package/build/typescript/attribute-reactions.d.ts +4 -0
- package/build/typescript/attribute-reactions.d.ts.map +1 -0
- package/build/typescript/constants.d.ts +27 -18
- package/build/typescript/constants.d.ts.map +1 -1
- package/build/typescript/custom-element-reactions.d.ts +6 -0
- package/build/typescript/custom-element-reactions.d.ts.map +1 -0
- package/build/typescript/dom-exception.d.ts +2 -0
- package/build/typescript/dom-exception.d.ts.map +1 -0
- package/build/typescript/extensions.d.ts +4 -0
- package/build/typescript/extensions.d.ts.map +1 -0
- package/build/typescript/hook-effects.d.ts +6 -0
- package/build/typescript/hook-effects.d.ts.map +1 -0
- package/build/typescript/hooks.d.ts +3 -3
- package/build/typescript/hooks.d.ts.map +1 -1
- package/build/typescript/index.d.ts +1 -0
- package/build/typescript/index.d.ts.map +1 -1
- package/build/typescript/names.d.ts +11 -0
- package/build/typescript/names.d.ts.map +1 -0
- package/build/typescript/selectors.d.ts +21 -22
- package/build/typescript/selectors.d.ts.map +1 -1
- package/build/typescript/serialization.d.ts.map +1 -1
- package/build/typescript/shared.d.ts +10 -0
- package/build/typescript/shared.d.ts.map +1 -1
- package/build/typescript/tests/ChildNode.test.d.ts +2 -0
- package/build/typescript/tests/ChildNode.test.d.ts.map +1 -0
- package/build/typescript/tests/MutationObserver.test.d.ts +2 -0
- package/build/typescript/tests/MutationObserver.test.d.ts.map +1 -0
- package/build/typescript/tests/adopt-inserted-subtrees.test.d.ts +2 -0
- package/build/typescript/tests/adopt-inserted-subtrees.test.d.ts.map +1 -0
- package/build/typescript/tests/attr-mutation.test.d.ts +2 -0
- package/build/typescript/tests/attr-mutation.test.d.ts.map +1 -0
- package/build/typescript/tests/child-node-before-after.test.d.ts +2 -0
- package/build/typescript/tests/child-node-before-after.test.d.ts.map +1 -0
- package/build/typescript/tests/child-node-replace-with.test.d.ts +2 -0
- package/build/typescript/tests/child-node-replace-with.test.d.ts.map +1 -0
- package/build/typescript/tests/clone-import-namespaces.test.d.ts +2 -0
- package/build/typescript/tests/clone-import-namespaces.test.d.ts.map +1 -0
- package/build/typescript/tests/constants.test.d.ts +2 -0
- package/build/typescript/tests/constants.test.d.ts.map +1 -0
- package/build/typescript/tests/create-element-namespaces.test.d.ts +2 -0
- package/build/typescript/tests/create-element-namespaces.test.d.ts.map +1 -0
- package/build/typescript/tests/create-text-node.test.d.ts +2 -0
- package/build/typescript/tests/create-text-node.test.d.ts.map +1 -0
- package/build/typescript/tests/custom-element-reactions.test.d.ts +2 -0
- package/build/typescript/tests/custom-element-reactions.test.d.ts.map +1 -0
- package/build/typescript/tests/custom-element-registry.test.d.ts +2 -0
- package/build/typescript/tests/custom-element-registry.test.d.ts.map +1 -0
- package/build/typescript/tests/custom-event.test.d.ts +2 -0
- package/build/typescript/tests/custom-event.test.d.ts.map +1 -0
- package/build/typescript/tests/document-clone-import-contract.test.d.ts +2 -0
- package/build/typescript/tests/document-clone-import-contract.test.d.ts.map +1 -0
- package/build/typescript/tests/document.test.d.ts +2 -0
- package/build/typescript/tests/document.test.d.ts.map +1 -0
- package/build/typescript/tests/dom-mutation-selector-errors.test.d.ts +2 -0
- package/build/typescript/tests/dom-mutation-selector-errors.test.d.ts.map +1 -0
- package/build/typescript/tests/event-dispatch.test.d.ts +2 -0
- package/build/typescript/tests/event-dispatch.test.d.ts.map +1 -0
- package/build/typescript/tests/event-target.test.d.ts +2 -0
- package/build/typescript/tests/event-target.test.d.ts.map +1 -0
- package/build/typescript/tests/event.test.d.ts +2 -0
- package/build/typescript/tests/event.test.d.ts.map +1 -0
- package/build/typescript/tests/extensions.test.d.ts +2 -0
- package/build/typescript/tests/extensions.test.d.ts.map +1 -0
- package/build/typescript/tests/get-elements-by-tag-name.test.d.ts +2 -0
- package/build/typescript/tests/get-elements-by-tag-name.test.d.ts.map +1 -0
- package/build/typescript/tests/getElementsByClassName.test.d.ts +2 -0
- package/build/typescript/tests/getElementsByClassName.test.d.ts.map +1 -0
- package/build/typescript/tests/hooks.test.d.ts +2 -0
- package/build/typescript/tests/hooks.test.d.ts.map +1 -0
- package/build/typescript/tests/inner-html-parsing.test.d.ts +2 -0
- package/build/typescript/tests/inner-html-parsing.test.d.ts.map +1 -0
- package/build/typescript/tests/is-default-namespace.test.d.ts +2 -0
- package/build/typescript/tests/is-default-namespace.test.d.ts.map +1 -0
- package/build/typescript/tests/name-and-namespace-normalization.test.d.ts +2 -0
- package/build/typescript/tests/name-and-namespace-normalization.test.d.ts.map +1 -0
- package/build/typescript/tests/named-node-map.test.d.ts +2 -0
- package/build/typescript/tests/named-node-map.test.d.ts.map +1 -0
- package/build/typescript/tests/namespaced-attribute-reactions.test.d.ts +2 -0
- package/build/typescript/tests/namespaced-attribute-reactions.test.d.ts.map +1 -0
- package/build/typescript/tests/node.test.d.ts +2 -0
- package/build/typescript/tests/node.test.d.ts.map +1 -0
- package/build/typescript/tests/parent-node-mutation-return-values.test.d.ts +2 -0
- package/build/typescript/tests/parent-node-mutation-return-values.test.d.ts.map +1 -0
- package/build/typescript/tests/parent-node-mutation-validation.test.d.ts +2 -0
- package/build/typescript/tests/parent-node-mutation-validation.test.d.ts.map +1 -0
- package/build/typescript/tests/parent-node.test.d.ts +2 -0
- package/build/typescript/tests/parent-node.test.d.ts.map +1 -0
- package/build/typescript/tests/serialization-template.test.d.ts +2 -0
- package/build/typescript/tests/serialization-template.test.d.ts.map +1 -0
- package/build/typescript/tests/slot-attribute.test.d.ts +2 -0
- package/build/typescript/tests/slot-attribute.test.d.ts.map +1 -0
- package/build/typescript/tests/text-content.test.d.ts +2 -0
- package/build/typescript/tests/text-content.test.d.ts.map +1 -0
- package/build/typescript/tests/toggle-attribute.test.d.ts +2 -0
- package/build/typescript/tests/toggle-attribute.test.d.ts.map +1 -0
- package/build/typescript/tests/wide-tree-traversal.test.d.ts +2 -0
- package/build/typescript/tests/wide-tree-traversal.test.d.ts.map +1 -0
- package/build/typescript/tests/window-set-global.test.d.ts +2 -0
- package/build/typescript/tests/window-set-global.test.d.ts.map +1 -0
- package/package.json +1 -1
- package/source/Attr.ts +60 -8
- package/source/CharacterData.ts +13 -0
- package/source/ChildNode.ts +107 -14
- package/source/Comment.ts +2 -2
- package/source/CustomElementRegistry.ts +56 -0
- package/source/CustomEvent.ts +2 -2
- package/source/Document.ts +104 -38
- package/source/DocumentFragment.ts +12 -2
- package/source/Element.ts +129 -14
- package/source/Event.ts +34 -32
- package/source/EventTarget.ts +203 -79
- package/source/HTMLTemplateElement.ts +2 -1
- package/source/MutationObserver.ts +279 -1
- package/source/NamedNodeMap.ts +141 -60
- package/source/Node.ts +70 -14
- package/source/NodeList.ts +13 -3
- package/source/ParentNode.ts +500 -88
- package/source/SVGElement.ts +2 -2
- package/source/Text.ts +2 -2
- package/source/Window.ts +156 -17
- package/source/attribute-reactions.ts +32 -0
- package/source/constants.ts +40 -17
- package/source/custom-element-reactions.ts +64 -0
- package/source/dom-exception.ts +14 -0
- package/source/extensions.ts +4 -0
- package/source/hook-effects.ts +56 -0
- package/source/hooks.ts +11 -3
- package/source/index.ts +1 -0
- package/source/names.ts +94 -0
- package/source/selectors.ts +301 -138
- package/source/serialization.ts +224 -66
- package/source/shared.ts +269 -40
- package/source/tests/ChildNode.test.ts +178 -0
- package/source/tests/MutationObserver.test.ts +303 -0
- package/source/tests/adopt-inserted-subtrees.test.ts +584 -0
- package/source/tests/attr-mutation.test.ts +112 -0
- package/source/tests/child-node-before-after.test.ts +421 -0
- package/source/tests/child-node-replace-with.test.ts +251 -0
- package/source/tests/clone-import-namespaces.test.ts +365 -0
- package/source/tests/constants.test.ts +46 -0
- package/source/tests/create-element-namespaces.test.ts +142 -0
- package/source/tests/create-text-node.test.ts +38 -0
- package/source/tests/custom-element-reactions.test.ts +600 -0
- package/source/tests/custom-element-registry.test.ts +137 -0
- package/source/tests/custom-event.test.ts +26 -0
- package/source/tests/document-clone-import-contract.test.ts +77 -0
- package/source/tests/document.test.ts +122 -0
- package/source/tests/dom-mutation-selector-errors.test.ts +484 -0
- package/source/tests/event-dispatch.test.ts +270 -0
- package/source/tests/event-target.test.ts +208 -0
- package/source/tests/event.test.ts +98 -0
- package/source/tests/extensions.test.ts +159 -0
- package/source/tests/get-elements-by-tag-name.test.ts +79 -0
- package/source/tests/getElementsByClassName.test.ts +109 -0
- package/source/tests/hooks.test.ts +43 -0
- package/source/tests/inner-html-parsing.test.ts +461 -0
- package/source/tests/is-default-namespace.test.ts +111 -0
- package/source/tests/name-and-namespace-normalization.test.ts +319 -0
- package/source/tests/named-node-map.test.ts +122 -0
- package/source/tests/namespaced-attribute-reactions.test.ts +141 -0
- package/source/tests/node.test.ts +56 -0
- package/source/tests/parent-node-mutation-return-values.test.ts +63 -0
- package/source/tests/parent-node-mutation-validation.test.ts +362 -0
- package/source/tests/parent-node.test.ts +169 -0
- package/source/tests/selectors.test.ts +533 -22
- package/source/tests/serialization-template.test.ts +232 -0
- package/source/tests/slot-attribute.test.ts +133 -0
- package/source/tests/text-content.test.ts +440 -0
- package/source/tests/toggle-attribute.test.ts +113 -0
- package/source/tests/wide-tree-traversal.test.ts +699 -0
- package/source/tests/window-set-global.test.ts +321 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {Window} from '../index.ts';
|
|
2
|
+
|
|
3
|
+
import {beforeEach, describe, expect, it} from 'vitest';
|
|
4
|
+
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
const window = new Window();
|
|
7
|
+
Window.setGlobalThis(window);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('ParentNode mutation return values', () => {
|
|
11
|
+
it('returns the removed child and preserves the remaining tree structure', () => {
|
|
12
|
+
const parent = document.createElement('div');
|
|
13
|
+
const first = document.createElement('span');
|
|
14
|
+
const child = document.createElement('em');
|
|
15
|
+
const last = document.createElement('strong');
|
|
16
|
+
parent.append(first, child, last);
|
|
17
|
+
|
|
18
|
+
expect(parent.removeChild(child)).toBe(child);
|
|
19
|
+
|
|
20
|
+
expect(Array.from(parent.childNodes)).toEqual([first, last]);
|
|
21
|
+
expect(first.nextSibling).toBe(last);
|
|
22
|
+
expect(last.previousSibling).toBe(first);
|
|
23
|
+
expect(child.parentNode).toBeNull();
|
|
24
|
+
expect(child.previousSibling).toBeNull();
|
|
25
|
+
expect(child.nextSibling).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('returns the replaced child and installs the replacement in its place', () => {
|
|
29
|
+
const parent = document.createElement('div');
|
|
30
|
+
const first = document.createElement('span');
|
|
31
|
+
const oldChild = document.createElement('em');
|
|
32
|
+
const last = document.createElement('strong');
|
|
33
|
+
const newChild = document.createElement('i');
|
|
34
|
+
parent.append(first, oldChild, last);
|
|
35
|
+
|
|
36
|
+
expect(parent.replaceChild(newChild, oldChild)).toBe(oldChild);
|
|
37
|
+
|
|
38
|
+
expect(Array.from(parent.childNodes)).toEqual([first, newChild, last]);
|
|
39
|
+
expect(first.nextSibling).toBe(newChild);
|
|
40
|
+
expect(newChild.previousSibling).toBe(first);
|
|
41
|
+
expect(newChild.nextSibling).toBe(last);
|
|
42
|
+
expect(last.previousSibling).toBe(newChild);
|
|
43
|
+
expect(newChild.parentNode).toBe(parent);
|
|
44
|
+
expect(oldChild.parentNode).toBeNull();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('returns the child when replacing it with itself without changing the tree', () => {
|
|
48
|
+
const parent = document.createElement('div');
|
|
49
|
+
const first = document.createElement('span');
|
|
50
|
+
const child = document.createElement('em');
|
|
51
|
+
const last = document.createElement('strong');
|
|
52
|
+
parent.append(first, child, last);
|
|
53
|
+
|
|
54
|
+
expect(parent.replaceChild(child, child)).toBe(child);
|
|
55
|
+
|
|
56
|
+
expect(Array.from(parent.childNodes)).toEqual([first, child, last]);
|
|
57
|
+
expect(first.nextSibling).toBe(child);
|
|
58
|
+
expect(child.previousSibling).toBe(first);
|
|
59
|
+
expect(child.nextSibling).toBe(last);
|
|
60
|
+
expect(last.previousSibling).toBe(child);
|
|
61
|
+
expect(child.parentNode).toBe(parent);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import {HOOKS, Window} from '../index.ts';
|
|
2
|
+
|
|
3
|
+
import {beforeEach, describe, expect, it, vi} from 'vitest';
|
|
4
|
+
|
|
5
|
+
let polyfillWindow: Window;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
polyfillWindow = new Window();
|
|
9
|
+
Window.setGlobalThis(polyfillWindow);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('ParentNode insertion validation', () => {
|
|
13
|
+
it('rejects inserting a node into itself without changing the tree', () => {
|
|
14
|
+
const parent = document.createElement('div');
|
|
15
|
+
const child = document.createElement('span');
|
|
16
|
+
parent.appendChild(child);
|
|
17
|
+
|
|
18
|
+
expect(() => parent.appendChild(parent)).toThrow();
|
|
19
|
+
|
|
20
|
+
expect(parent.parentNode).toBeNull();
|
|
21
|
+
expect(Array.from(parent.childNodes)).toEqual([child]);
|
|
22
|
+
expect(child.parentNode).toBe(parent);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('rejects inserting an ancestor without changing either tree', () => {
|
|
26
|
+
const ancestor = document.createElement('section');
|
|
27
|
+
const parent = document.createElement('div');
|
|
28
|
+
const child = document.createElement('span');
|
|
29
|
+
ancestor.appendChild(parent);
|
|
30
|
+
parent.appendChild(child);
|
|
31
|
+
|
|
32
|
+
expect(() => parent.insertBefore(ancestor, child)).toThrow();
|
|
33
|
+
|
|
34
|
+
expect(ancestor.parentNode).toBeNull();
|
|
35
|
+
expect(Array.from(ancestor.childNodes)).toEqual([parent]);
|
|
36
|
+
expect(parent.parentNode).toBe(ancestor);
|
|
37
|
+
expect(Array.from(parent.childNodes)).toEqual([child]);
|
|
38
|
+
expect(child.parentNode).toBe(parent);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('preserves an attached child when the reference belongs to another parent', () => {
|
|
42
|
+
const source = document.createElement('div');
|
|
43
|
+
const first = document.createElement('span');
|
|
44
|
+
const child = document.createElement('em');
|
|
45
|
+
const last = document.createElement('strong');
|
|
46
|
+
const destination = document.createElement('div');
|
|
47
|
+
const foreignParent = document.createElement('div');
|
|
48
|
+
const foreignReference = document.createElement('span');
|
|
49
|
+
source.append(first, child, last);
|
|
50
|
+
foreignParent.appendChild(foreignReference);
|
|
51
|
+
|
|
52
|
+
expect(() => destination.insertBefore(child, foreignReference)).toThrow();
|
|
53
|
+
|
|
54
|
+
expect(Array.from(source.childNodes)).toEqual([first, child, last]);
|
|
55
|
+
expect(first.nextSibling).toBe(child);
|
|
56
|
+
expect(child.previousSibling).toBe(first);
|
|
57
|
+
expect(child.nextSibling).toBe(last);
|
|
58
|
+
expect(last.previousSibling).toBe(child);
|
|
59
|
+
expect(child.parentNode).toBe(source);
|
|
60
|
+
expect(Array.from(destination.childNodes)).toEqual([]);
|
|
61
|
+
expect(Array.from(foreignParent.childNodes)).toEqual([foreignReference]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('does nothing when inserting a node before itself', () => {
|
|
65
|
+
const parent = document.createElement('div');
|
|
66
|
+
const first = document.createElement('span');
|
|
67
|
+
const child = document.createElement('em');
|
|
68
|
+
const last = document.createElement('strong');
|
|
69
|
+
parent.append(first, child, last);
|
|
70
|
+
|
|
71
|
+
expect(parent.insertBefore(child, child)).toBe(child);
|
|
72
|
+
|
|
73
|
+
expect(Array.from(parent.childNodes)).toEqual([first, child, last]);
|
|
74
|
+
expect(first.nextSibling).toBe(child);
|
|
75
|
+
expect(child.previousSibling).toBe(first);
|
|
76
|
+
expect(child.nextSibling).toBe(last);
|
|
77
|
+
expect(last.previousSibling).toBe(child);
|
|
78
|
+
expect(child.parentNode).toBe(parent);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('preserves self-insertion lifecycle and observer effects', () => {
|
|
82
|
+
const calls: string[] = [];
|
|
83
|
+
class IdentityInsertionElement extends HTMLElement {
|
|
84
|
+
connectedCallback() {
|
|
85
|
+
calls.push('connected');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
disconnectedCallback() {
|
|
89
|
+
calls.push('disconnected');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
customElements.define(
|
|
93
|
+
'identity-insertion-element',
|
|
94
|
+
IdentityInsertionElement,
|
|
95
|
+
);
|
|
96
|
+
const parent = document.createElement('div');
|
|
97
|
+
const child = document.createElement('identity-insertion-element');
|
|
98
|
+
parent.appendChild(child);
|
|
99
|
+
document.body.appendChild(parent);
|
|
100
|
+
calls.length = 0;
|
|
101
|
+
const observer = new MutationObserver(() => {});
|
|
102
|
+
observer.observe(parent, {childList: true});
|
|
103
|
+
|
|
104
|
+
parent.insertBefore(child, child);
|
|
105
|
+
|
|
106
|
+
expect(calls).toEqual(['disconnected', 'connected']);
|
|
107
|
+
expect(
|
|
108
|
+
observer.takeRecords().map((record) => ({
|
|
109
|
+
added: record.addedNodes.length,
|
|
110
|
+
removed: record.removedNodes.length,
|
|
111
|
+
})),
|
|
112
|
+
).toEqual([
|
|
113
|
+
{added: 0, removed: 1},
|
|
114
|
+
{added: 1, removed: 0},
|
|
115
|
+
]);
|
|
116
|
+
observer.disconnect();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('preserves valid move semantics for an attached node', () => {
|
|
120
|
+
const parent = document.createElement('div');
|
|
121
|
+
const first = document.createElement('span');
|
|
122
|
+
const child = document.createElement('em');
|
|
123
|
+
const last = document.createElement('strong');
|
|
124
|
+
parent.append(first, child, last);
|
|
125
|
+
|
|
126
|
+
parent.insertBefore(child, first);
|
|
127
|
+
|
|
128
|
+
expect(Array.from(parent.childNodes)).toEqual([child, first, last]);
|
|
129
|
+
expect(child.previousSibling).toBeNull();
|
|
130
|
+
expect(child.nextSibling).toBe(first);
|
|
131
|
+
expect(first.previousSibling).toBe(child);
|
|
132
|
+
expect(first.nextSibling).toBe(last);
|
|
133
|
+
expect(last.previousSibling).toBe(first);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('does not move fragment children when the reference is invalid', () => {
|
|
137
|
+
const parent = document.createElement('div');
|
|
138
|
+
const existing = document.createElement('span');
|
|
139
|
+
const fragment = document.createDocumentFragment();
|
|
140
|
+
const first = document.createElement('em');
|
|
141
|
+
const last = document.createElement('strong');
|
|
142
|
+
const foreignReference = document.createElement('span');
|
|
143
|
+
parent.appendChild(existing);
|
|
144
|
+
fragment.append(first, last);
|
|
145
|
+
|
|
146
|
+
expect(() => parent.insertBefore(fragment, foreignReference)).toThrow();
|
|
147
|
+
|
|
148
|
+
expect(Array.from(parent.childNodes)).toEqual([existing]);
|
|
149
|
+
expect(Array.from(fragment.childNodes)).toEqual([first, last]);
|
|
150
|
+
expect(first.parentNode).toBe(fragment);
|
|
151
|
+
expect(first.nextSibling).toBe(last);
|
|
152
|
+
expect(last.previousSibling).toBe(first);
|
|
153
|
+
expect(last.parentNode).toBe(fragment);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('rejects inserting a fragment into its descendant without moving children', () => {
|
|
157
|
+
const fragment = document.createDocumentFragment();
|
|
158
|
+
const ancestor = document.createElement('section');
|
|
159
|
+
const parent = document.createElement('div');
|
|
160
|
+
fragment.appendChild(ancestor);
|
|
161
|
+
ancestor.appendChild(parent);
|
|
162
|
+
|
|
163
|
+
expect(() => parent.appendChild(fragment)).toThrow();
|
|
164
|
+
|
|
165
|
+
expect(Array.from(fragment.childNodes)).toEqual([ancestor]);
|
|
166
|
+
expect(ancestor.parentNode).toBe(fragment);
|
|
167
|
+
expect(Array.from(ancestor.childNodes)).toEqual([parent]);
|
|
168
|
+
expect(parent.parentNode).toBe(ancestor);
|
|
169
|
+
expect(Array.from(parent.childNodes)).toEqual([]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('rejects inserting a template into its own content without changing state', () => {
|
|
173
|
+
const parent = document.createElement('div');
|
|
174
|
+
const template = document.createElement('template');
|
|
175
|
+
const content = template.content;
|
|
176
|
+
parent.appendChild(template);
|
|
177
|
+
const removeChild = vi.fn();
|
|
178
|
+
polyfillWindow[HOOKS].removeChild = removeChild;
|
|
179
|
+
|
|
180
|
+
expect(() => content.appendChild(template)).toThrow();
|
|
181
|
+
|
|
182
|
+
expect(Array.from(parent.childNodes)).toEqual([template]);
|
|
183
|
+
expect(template.parentNode).toBe(parent);
|
|
184
|
+
expect(Array.from(content.childNodes)).toEqual([]);
|
|
185
|
+
expect(content.parentNode).toBeNull();
|
|
186
|
+
expect(template.contains(content)).toBe(false);
|
|
187
|
+
expect(removeChild).not.toHaveBeenCalled();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('rejects mutually nesting templates through their content fragments', () => {
|
|
191
|
+
const parent = document.createElement('div');
|
|
192
|
+
const outer = document.createElement('template');
|
|
193
|
+
const inner = document.createElement('template');
|
|
194
|
+
parent.appendChild(outer);
|
|
195
|
+
outer.content.appendChild(inner);
|
|
196
|
+
const removeChild = vi.fn();
|
|
197
|
+
polyfillWindow[HOOKS].removeChild = removeChild;
|
|
198
|
+
|
|
199
|
+
expect(() => inner.content.appendChild(outer)).toThrow();
|
|
200
|
+
|
|
201
|
+
expect(Array.from(parent.childNodes)).toEqual([outer]);
|
|
202
|
+
expect(outer.parentNode).toBe(parent);
|
|
203
|
+
expect(Array.from(outer.content.childNodes)).toEqual([inner]);
|
|
204
|
+
expect(inner.parentNode).toBe(outer.content);
|
|
205
|
+
expect(Array.from(inner.content.childNodes)).toEqual([]);
|
|
206
|
+
expect(removeChild).not.toHaveBeenCalled();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('rejects nesting an ancestor template through nested template content', () => {
|
|
210
|
+
const parent = document.createElement('div');
|
|
211
|
+
const outer = document.createElement('template');
|
|
212
|
+
const wrapper = document.createElement('section');
|
|
213
|
+
const inner = document.createElement('template');
|
|
214
|
+
parent.appendChild(outer);
|
|
215
|
+
outer.content.appendChild(wrapper);
|
|
216
|
+
wrapper.appendChild(inner);
|
|
217
|
+
const removeChild = vi.fn();
|
|
218
|
+
polyfillWindow[HOOKS].removeChild = removeChild;
|
|
219
|
+
|
|
220
|
+
expect(() => inner.content.appendChild(outer)).toThrow();
|
|
221
|
+
|
|
222
|
+
expect(Array.from(parent.childNodes)).toEqual([outer]);
|
|
223
|
+
expect(outer.parentNode).toBe(parent);
|
|
224
|
+
expect(Array.from(outer.content.childNodes)).toEqual([wrapper]);
|
|
225
|
+
expect(wrapper.parentNode).toBe(outer.content);
|
|
226
|
+
expect(Array.from(wrapper.childNodes)).toEqual([inner]);
|
|
227
|
+
expect(inner.parentNode).toBe(wrapper);
|
|
228
|
+
expect(Array.from(inner.content.childNodes)).toEqual([]);
|
|
229
|
+
expect(removeChild).not.toHaveBeenCalled();
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe('ParentNode replacement validation', () => {
|
|
234
|
+
it('replaces a child with its next sibling without detaching the sibling', () => {
|
|
235
|
+
const parent = document.createElement('div');
|
|
236
|
+
const first = document.createElement('span');
|
|
237
|
+
const oldChild = document.createElement('em');
|
|
238
|
+
const nextSibling = document.createElement('strong');
|
|
239
|
+
const last = document.createElement('span');
|
|
240
|
+
parent.append(first, oldChild, nextSibling, last);
|
|
241
|
+
|
|
242
|
+
parent.replaceChild(nextSibling, oldChild);
|
|
243
|
+
|
|
244
|
+
expect(Array.from(parent.childNodes)).toEqual([first, nextSibling, last]);
|
|
245
|
+
expect(first.nextSibling).toBe(nextSibling);
|
|
246
|
+
expect(nextSibling.previousSibling).toBe(first);
|
|
247
|
+
expect(nextSibling.nextSibling).toBe(last);
|
|
248
|
+
expect(last.previousSibling).toBe(nextSibling);
|
|
249
|
+
expect(nextSibling.parentNode).toBe(parent);
|
|
250
|
+
expect(oldChild.parentNode).toBeNull();
|
|
251
|
+
expect(oldChild.previousSibling).toBeNull();
|
|
252
|
+
expect(oldChild.nextSibling).toBeNull();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('rejects replacing a child with the parent without removing the child', () => {
|
|
256
|
+
const parent = document.createElement('div');
|
|
257
|
+
const oldChild = document.createElement('span');
|
|
258
|
+
parent.appendChild(oldChild);
|
|
259
|
+
|
|
260
|
+
expect(() => parent.replaceChild(parent, oldChild)).toThrow();
|
|
261
|
+
|
|
262
|
+
expect(parent.parentNode).toBeNull();
|
|
263
|
+
expect(Array.from(parent.childNodes)).toEqual([oldChild]);
|
|
264
|
+
expect(oldChild.parentNode).toBe(parent);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('rejects replacing a child with an ancestor without changing either tree', () => {
|
|
268
|
+
const ancestor = document.createElement('section');
|
|
269
|
+
const parent = document.createElement('div');
|
|
270
|
+
const oldChild = document.createElement('span');
|
|
271
|
+
ancestor.appendChild(parent);
|
|
272
|
+
parent.appendChild(oldChild);
|
|
273
|
+
|
|
274
|
+
expect(() => parent.replaceChild(ancestor, oldChild)).toThrow();
|
|
275
|
+
|
|
276
|
+
expect(ancestor.parentNode).toBeNull();
|
|
277
|
+
expect(Array.from(ancestor.childNodes)).toEqual([parent]);
|
|
278
|
+
expect(parent.parentNode).toBe(ancestor);
|
|
279
|
+
expect(Array.from(parent.childNodes)).toEqual([oldChild]);
|
|
280
|
+
expect(oldChild.parentNode).toBe(parent);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('preserves the replacement node when the old child belongs elsewhere', () => {
|
|
284
|
+
const source = document.createElement('div');
|
|
285
|
+
const first = document.createElement('span');
|
|
286
|
+
const replacement = document.createElement('em');
|
|
287
|
+
const last = document.createElement('strong');
|
|
288
|
+
const parent = document.createElement('div');
|
|
289
|
+
const existing = document.createElement('span');
|
|
290
|
+
const foreignParent = document.createElement('div');
|
|
291
|
+
const foreignOldChild = document.createElement('span');
|
|
292
|
+
source.append(first, replacement, last);
|
|
293
|
+
parent.appendChild(existing);
|
|
294
|
+
foreignParent.appendChild(foreignOldChild);
|
|
295
|
+
|
|
296
|
+
expect(() => parent.replaceChild(replacement, foreignOldChild)).toThrow();
|
|
297
|
+
|
|
298
|
+
expect(Array.from(source.childNodes)).toEqual([first, replacement, last]);
|
|
299
|
+
expect(first.nextSibling).toBe(replacement);
|
|
300
|
+
expect(replacement.previousSibling).toBe(first);
|
|
301
|
+
expect(replacement.nextSibling).toBe(last);
|
|
302
|
+
expect(last.previousSibling).toBe(replacement);
|
|
303
|
+
expect(replacement.parentNode).toBe(source);
|
|
304
|
+
expect(Array.from(parent.childNodes)).toEqual([existing]);
|
|
305
|
+
expect(Array.from(foreignParent.childNodes)).toEqual([foreignOldChild]);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('preserves final position when replacing a child with itself', () => {
|
|
309
|
+
const parent = document.createElement('div');
|
|
310
|
+
const first = document.createElement('span');
|
|
311
|
+
const child = document.createElement('em');
|
|
312
|
+
const last = document.createElement('strong');
|
|
313
|
+
parent.append(first, child, last);
|
|
314
|
+
|
|
315
|
+
parent.replaceChild(child, child);
|
|
316
|
+
|
|
317
|
+
expect(Array.from(parent.childNodes)).toEqual([first, child, last]);
|
|
318
|
+
expect(first.nextSibling).toBe(child);
|
|
319
|
+
expect(child.previousSibling).toBe(first);
|
|
320
|
+
expect(child.nextSibling).toBe(last);
|
|
321
|
+
expect(last.previousSibling).toBe(child);
|
|
322
|
+
expect(child.parentNode).toBe(parent);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('preserves self-replacement lifecycle and observer effects', () => {
|
|
326
|
+
const calls: string[] = [];
|
|
327
|
+
class IdentityReplacementElement extends HTMLElement {
|
|
328
|
+
connectedCallback() {
|
|
329
|
+
calls.push('connected');
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
disconnectedCallback() {
|
|
333
|
+
calls.push('disconnected');
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
customElements.define(
|
|
337
|
+
'identity-replacement-element',
|
|
338
|
+
IdentityReplacementElement,
|
|
339
|
+
);
|
|
340
|
+
const parent = document.createElement('div');
|
|
341
|
+
const child = document.createElement('identity-replacement-element');
|
|
342
|
+
parent.appendChild(child);
|
|
343
|
+
document.body.appendChild(parent);
|
|
344
|
+
calls.length = 0;
|
|
345
|
+
const observer = new MutationObserver(() => {});
|
|
346
|
+
observer.observe(parent, {childList: true});
|
|
347
|
+
|
|
348
|
+
parent.replaceChild(child, child);
|
|
349
|
+
|
|
350
|
+
expect(calls).toEqual(['disconnected', 'connected']);
|
|
351
|
+
expect(
|
|
352
|
+
observer.takeRecords().map((record) => ({
|
|
353
|
+
added: record.addedNodes.length,
|
|
354
|
+
removed: record.removedNodes.length,
|
|
355
|
+
})),
|
|
356
|
+
).toEqual([
|
|
357
|
+
{added: 0, removed: 1},
|
|
358
|
+
{added: 1, removed: 0},
|
|
359
|
+
]);
|
|
360
|
+
observer.disconnect();
|
|
361
|
+
});
|
|
362
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {Window} from '../index.ts';
|
|
2
|
+
|
|
3
|
+
import {beforeEach, describe, expect, it} from 'vitest';
|
|
4
|
+
|
|
5
|
+
function siblingChain(parent: ParentNode) {
|
|
6
|
+
const names: string[] = [];
|
|
7
|
+
for (let node = parent.firstChild; node; node = node.nextSibling) {
|
|
8
|
+
names.push(node.nodeName.toLowerCase());
|
|
9
|
+
}
|
|
10
|
+
return names;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function childNodeNames(parent: ParentNode) {
|
|
14
|
+
return Array.from(parent.childNodes, (node) => node.nodeName.toLowerCase());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
const window = new Window();
|
|
19
|
+
Window.setGlobalThis(window);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('ParentNode.appendChild', () => {
|
|
23
|
+
it('returns the appended child', () => {
|
|
24
|
+
const parent = document.createElement('div');
|
|
25
|
+
const child = document.createElement('span');
|
|
26
|
+
|
|
27
|
+
expect(parent.appendChild(child)).toBe(child);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('ParentNode.insertBefore', () => {
|
|
32
|
+
it('links an element inserted before a middle child into tree order', () => {
|
|
33
|
+
const parent = document.createElement('div');
|
|
34
|
+
const first = document.createElement('span');
|
|
35
|
+
const middle = document.createElement('em');
|
|
36
|
+
const last = document.createElement('strong');
|
|
37
|
+
|
|
38
|
+
parent.appendChild(first);
|
|
39
|
+
parent.appendChild(last);
|
|
40
|
+
|
|
41
|
+
expect(parent.insertBefore(middle, last)).toBe(middle);
|
|
42
|
+
expect(Array.from(parent.childNodes)).toEqual([first, middle, last]);
|
|
43
|
+
expect(first.nextSibling).toBe(middle);
|
|
44
|
+
expect(middle.previousSibling).toBe(first);
|
|
45
|
+
expect(middle.nextSibling).toBe(last);
|
|
46
|
+
expect(last.previousSibling).toBe(middle);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('inserts before the first child', () => {
|
|
50
|
+
const existing = document.createElement('existing-child');
|
|
51
|
+
document.body.appendChild(existing);
|
|
52
|
+
|
|
53
|
+
const inserted = document.createElement('inserted-child');
|
|
54
|
+
document.body.insertBefore(inserted, existing);
|
|
55
|
+
|
|
56
|
+
expect(siblingChain(document.body)).toStrictEqual([
|
|
57
|
+
'inserted-child',
|
|
58
|
+
'existing-child',
|
|
59
|
+
]);
|
|
60
|
+
expect(document.body.firstChild).toBe(inserted);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('keeps the sibling chain and childNodes in agreement', () => {
|
|
64
|
+
const anchor = document.createElement('anchor-child');
|
|
65
|
+
document.body.appendChild(anchor);
|
|
66
|
+
|
|
67
|
+
for (let i = 0; i < 3; i++) {
|
|
68
|
+
document.body.insertBefore(document.createElement(`child-${i}`), anchor);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
expect(siblingChain(document.body)).toStrictEqual(
|
|
72
|
+
childNodeNames(document.body),
|
|
73
|
+
);
|
|
74
|
+
expect(siblingChain(document.body)).toStrictEqual([
|
|
75
|
+
'child-0',
|
|
76
|
+
'child-1',
|
|
77
|
+
'child-2',
|
|
78
|
+
'anchor-child',
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('finds a node inserted before a non-first child by selector', () => {
|
|
83
|
+
const style = document.createElement('style');
|
|
84
|
+
document.body.appendChild(style);
|
|
85
|
+
|
|
86
|
+
const modal = document.createElement('s-modal');
|
|
87
|
+
modal.setAttribute('id', 'add-zone');
|
|
88
|
+
document.body.insertBefore(modal, style);
|
|
89
|
+
|
|
90
|
+
expect(document.querySelector('s-modal#add-zone')).toBe(modal);
|
|
91
|
+
expect(document.querySelectorAll('s-modal')).toHaveLength(1);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('inserts the children of a document fragment in order', () => {
|
|
95
|
+
const anchor = document.createElement('anchor-child');
|
|
96
|
+
document.body.appendChild(anchor);
|
|
97
|
+
|
|
98
|
+
const fragment = document.createDocumentFragment();
|
|
99
|
+
fragment.append(
|
|
100
|
+
document.createElement('fragment-first'),
|
|
101
|
+
document.createElement('fragment-last'),
|
|
102
|
+
);
|
|
103
|
+
document.body.insertBefore(fragment, anchor);
|
|
104
|
+
|
|
105
|
+
expect(siblingChain(document.body)).toStrictEqual([
|
|
106
|
+
'fragment-first',
|
|
107
|
+
'fragment-last',
|
|
108
|
+
'anchor-child',
|
|
109
|
+
]);
|
|
110
|
+
expect(siblingChain(document.body)).toStrictEqual(
|
|
111
|
+
childNodeNames(document.body),
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('relinks a node moved from later to earlier in the same parent', () => {
|
|
116
|
+
const first = document.createElement('first-child');
|
|
117
|
+
const middle = document.createElement('middle-child');
|
|
118
|
+
const last = document.createElement('last-child');
|
|
119
|
+
document.body.append(first, middle, last);
|
|
120
|
+
|
|
121
|
+
document.body.insertBefore(last, middle);
|
|
122
|
+
|
|
123
|
+
expect(siblingChain(document.body)).toStrictEqual([
|
|
124
|
+
'first-child',
|
|
125
|
+
'last-child',
|
|
126
|
+
'middle-child',
|
|
127
|
+
]);
|
|
128
|
+
expect(siblingChain(document.body)).toStrictEqual(
|
|
129
|
+
childNodeNames(document.body),
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('ParentNode.prepend', () => {
|
|
135
|
+
it('prepends multiple nodes ahead of an existing child', () => {
|
|
136
|
+
const existing = document.createElement('existing-child');
|
|
137
|
+
document.body.appendChild(existing);
|
|
138
|
+
|
|
139
|
+
document.body.prepend(
|
|
140
|
+
document.createElement('prepended-first'),
|
|
141
|
+
document.createElement('prepended-last'),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
expect(siblingChain(document.body)).toStrictEqual([
|
|
145
|
+
'prepended-first',
|
|
146
|
+
'prepended-last',
|
|
147
|
+
'existing-child',
|
|
148
|
+
]);
|
|
149
|
+
expect(siblingChain(document.body)).toStrictEqual(
|
|
150
|
+
childNodeNames(document.body),
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('ChildNode.after', () => {
|
|
156
|
+
it('inserts after a non-last child', () => {
|
|
157
|
+
const first = document.createElement('first-child');
|
|
158
|
+
const last = document.createElement('last-child');
|
|
159
|
+
document.body.append(first, last);
|
|
160
|
+
|
|
161
|
+
first.after(document.createElement('inserted-child'));
|
|
162
|
+
|
|
163
|
+
expect(siblingChain(document.body)).toStrictEqual([
|
|
164
|
+
'first-child',
|
|
165
|
+
'inserted-child',
|
|
166
|
+
'last-child',
|
|
167
|
+
]);
|
|
168
|
+
});
|
|
169
|
+
});
|