Skip to content

Commit 1bd17dd

Browse files
Add test to ensure client-side parser works with DOMParser
Confirm that for the client parser, if the first HTML element has attributes, it should properly match only the tag name and no longer throw an error. Issue #23
1 parent 2dfffb3 commit 1bd17dd

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

test/html-to-dom.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,35 @@ describe('html-to-dom', function() {
5555
data.html.comment +
5656
data.html.script
5757
);
58-
helpers.deepEqualCircular(htmlToDOMClient(html), htmlToDOMServer(html));
58+
59+
helpers.deepEqualCircular(
60+
htmlToDOMClient(html),
61+
htmlToDOMServer(html)
62+
);
5963
});
6064

65+
it('works with `window.DOMParser`', function() {
66+
var html = (
67+
data.html.attributes +
68+
data.html.nested +
69+
data.html.comment +
70+
data.html.script
71+
);
72+
73+
// mock `window.DOMParser`
74+
// https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
75+
window.DOMParser = function() {
76+
this.parseFromString = function(html) {
77+
jsdomify.create(html);
78+
return document;
79+
};
80+
};
81+
82+
helpers.deepEqualCircular(
83+
htmlToDOMClient(html),
84+
htmlToDOMServer(html)
85+
);
86+
});
6187
});
6288

6389
});

0 commit comments

Comments
 (0)