Skip to content

Commit

Permalink
fix(client): serialise DOM objects
Browse files Browse the repository at this point in the history
DOM elements and nodes are now serialised using dom-serrialize.

Closes #1106
  • Loading branch information
dignifiedquire committed Jul 3, 2015
1 parent cc15dc4 commit 1f73be4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/stringify.js
@@ -1,3 +1,4 @@
var serialize = require('dom-serialize')
var instanceOf = require('./util').instanceOf

var stringify = function stringify (obj, depth) {
Expand Down Expand Up @@ -37,6 +38,8 @@ var stringify = function stringify (obj, depth) {
return '<!--' + obj.nodeValue + '-->'
} 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') {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion test/client/.eslintrc
@@ -1,5 +1,6 @@
{
"env": {
"jasmine": true
"jasmine": true,
"browser": true
}
}
6 changes: 6 additions & 0 deletions test/client/stringify.spec.js
Expand Up @@ -61,6 +61,12 @@ describe('stringify', function () {
expect(stringify(div)).to.be.eql('<div>some <span>text</span></div>')
})

it('should serialize DOMParser objects', function () {
var parser = new DOMParser()
var doc = parser.parseFromString('<test></test>', 'application/xml')
expect(stringify(doc)).to.be.eql('<test></test>')
})

it('should serialize across iframes', function () {
var div = document.createElement('div')
expect(__karma__.stringify(div)).to.be.eql('<div></div>')
Expand Down

0 comments on commit 1f73be4

Please sign in to comment.