Skip to content
Open
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
2 changes: 1 addition & 1 deletion cjs/interface/mutation-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const moCallback = (element, parentNode) => {
) {
const {callback, records, scheduled} = observer;
records.push(createRecord(
'childList', target, element,
'childList', parentNode || element.parentNode, element,
parentNode ? [] : [element], parentNode ? [element] : []
));
if (!scheduled) {
Expand Down
2 changes: 1 addition & 1 deletion esm/interface/mutation-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const moCallback = (element, parentNode) => {
) {
const {callback, records, scheduled} = observer;
records.push(createRecord(
'childList', target, element,
'childList', parentNode || element.parentNode, element,
parentNode ? [] : [element], parentNode ? [element] : []
));
if (!scheduled) {
Expand Down
51 changes: 51 additions & 0 deletions test/interface/mutation-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,55 @@ let {document: newDoc} = parseHTML('<html />');
true,
'MutationObserver addedNodes on html'
);
args = null;
observer.disconnect();
const bodyTarget = newDoc.body;
observer.observe(newDoc, {
childList: true,
subtree: true
});
bodyTarget.appendChild(newDoc.createTextNode(''));
await milliseconds(10);

assert(
checkRecord(
{target: bodyTarget, type: "childList", addedNodes: [bodyTarget.lastChild]},
args[0]
),
true,
'MutationObserver target is the parent of an inserted text node'
);
args = null;
const nestedDiv = newDoc.createElement('div');
bodyTarget.appendChild(nestedDiv);
await milliseconds(10);
args = null;
const spanChild = newDoc.createElement('span');
nestedDiv.appendChild(spanChild);
await milliseconds(10);

assert(
checkRecord(
{target: nestedDiv, type: "childList", addedNodes: [spanChild]},
args[0]
),
true,
'MutationObserver target is the parent of an inserted element'
);
args = null;
const removedChild = newDoc.createElement('b');
bodyTarget.appendChild(removedChild);
await milliseconds(10);
args = null;
bodyTarget.removeChild(removedChild);
await milliseconds(10);

assert(
checkRecord(
{target: bodyTarget, type: "childList", removedNodes: [removedChild]},
args[0]
),
true,
'MutationObserver target is the old parent of a removed child'
);
})();