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; diff --git a/src/nodejs-pal-builder.ts b/src/nodejs-pal-builder.ts index a0b7edc..aa114ec 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);