From 0dc050bb54e50fad5c1de5614b275ab7b227d0a4 Mon Sep 17 00:00:00 2001 From: Mikael Kohlmyr Date: Fri, 2 Feb 2018 17:04:27 +0000 Subject: [PATCH 1/2] add failing test for character data --- spec/mutation-observer.spec.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spec/mutation-observer.spec.ts b/spec/mutation-observer.spec.ts index 1a10667..d4990d1 100644 --- a/spec/mutation-observer.spec.ts +++ b/spec/mutation-observer.spec.ts @@ -77,6 +77,33 @@ describe("MutationObserver", () => { text.nodeValue = "B"; }); + it("character data changes trigger mutation event", function (done) { + var pal = buildPal(); + var dom = pal.dom; + var document = pal.global.window.document; + var text = document.createTextNode("A"); + + var observer = dom.createMutationObserver((changes) => { + try { + expect(changes.length).toBe(1); + expect(changes[0].oldValue).toBe("A"); + } + catch (err) { + fail(); + } + finally { + observer.disconnect(); + done(); + } + }); + + observer.observe(text, { + characterData: true + }); + + text.data = "B"; + }); + it("child-node changes trigger mutation event", function (done) { var pal = buildPal(); var dom = pal.dom; From 130666c0077589e0bdd3478c384a4295a691a53a Mon Sep 17 00:00:00 2001 From: Mikael Kohlmyr Date: Fri, 2 Feb 2018 17:11:47 +0000 Subject: [PATCH 2/2] fix failing test for character data changes in mutation observer --- src/nodejs-pal-builder.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/nodejs-pal-builder.ts b/src/nodejs-pal-builder.ts index 24d429d..9c0656e 100644 --- a/src/nodejs-pal-builder.ts +++ b/src/nodejs-pal-builder.ts @@ -73,6 +73,10 @@ function patchNotifyChange(window: Window) { intersectSetter(node_proto, "nodeValue", notify); intersectSetter(node_proto, "textContent", notify); + let char_proto = (window)._core.CharacterData.prototype; + + intersectSetter(char_proto, "data", notify); + let element_proto = (window)._core.Element.prototype; intersectMethod(element_proto, "setAttribute", notify);