From 1f73be4f94415947b286dadd068920bd8fa2b142 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Fri, 3 Jul 2015 10:16:24 +0200 Subject: [PATCH] fix(client): serialise DOM objects DOM elements and nodes are now serialised using dom-serrialize. Closes #1106 --- client/stringify.js | 3 +++ package.json | 1 + test/client/.eslintrc | 3 ++- test/client/stringify.spec.js | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/client/stringify.js b/client/stringify.js index f72e2e630..ed83c40e2 100644 --- a/client/stringify.js +++ b/client/stringify.js @@ -1,3 +1,4 @@ +var serialize = require('dom-serialize') var instanceOf = require('./util').instanceOf var stringify = function stringify (obj, depth) { @@ -37,6 +38,8 @@ var stringify = function stringify (obj, depth) { return '' } else if (obj.outerHTML) { return obj.outerHTML + } else if (obj.tagName || obj.nodeName) { + return serialize(obj) } else { var constructor = 'Object' if (obj.constructor && typeof obj.constructor === 'function') { diff --git a/package.json b/package.json index a2212e8fd..27bb35f9e 100644 --- a/package.json +++ b/package.json @@ -205,6 +205,7 @@ "connect": "^3.3.5", "core-js": "^0.9.17", "di": "^0.0.1", + "dom-serialize": "^2.2.0", "expand-braces": "^0.1.1", "glob": "^5.0.10", "graceful-fs": "^3.0.6", diff --git a/test/client/.eslintrc b/test/client/.eslintrc index 8f99b3e1e..7242ddf13 100644 --- a/test/client/.eslintrc +++ b/test/client/.eslintrc @@ -1,5 +1,6 @@ { "env": { - "jasmine": true + "jasmine": true, + "browser": true } } \ No newline at end of file diff --git a/test/client/stringify.spec.js b/test/client/stringify.spec.js index 517e47630..18dd34485 100644 --- a/test/client/stringify.spec.js +++ b/test/client/stringify.spec.js @@ -61,6 +61,12 @@ describe('stringify', function () { expect(stringify(div)).to.be.eql('
some text
') }) + it('should serialize DOMParser objects', function () { + var parser = new DOMParser() + var doc = parser.parseFromString('', 'application/xml') + expect(stringify(doc)).to.be.eql('') + }) + it('should serialize across iframes', function () { var div = document.createElement('div') expect(__karma__.stringify(div)).to.be.eql('
')