Skip to content

Commit 3583224

Browse files
Sebmasterdomenic
authored andcommitted
Fix failing tests to use new serialization method
1 parent 56aae9f commit 3583224

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

test/browser/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var dom = require("../../lib/jsdom/level2/core").dom.level2.core;
22
var jsdom = require('../../lib/jsdom');
3+
var serializeDocument = require('../../lib/jsdom').serializeDocument;
34
var browser;
45

56
exports.tests = {
@@ -184,7 +185,7 @@ exports.tests = {
184185
var doctype = dom.createDocumentType('html');
185186
var document = dom.createDocument(null, null, doctype);
186187
var regexp = /^\s*<!DOCTYPE html>/;
187-
test.ok(regexp.test(document.outerHTML), 'HTML 5 doctype did not serialize correctly');
188+
test.ok(regexp.test(serializeDocument(document)), 'HTML 5 doctype did not serialize correctly');
188189
test.done();
189190
},
190191

@@ -193,7 +194,7 @@ exports.tests = {
193194
var doctype = dom.createDocumentType('html', '-//W3C//DTD HTML 4.01//EN', 'http://www.w3.org/TR/html4/strict.dtd');
194195
var document = dom.createDocument(null, null, doctype);
195196
var regexp = /^\s*<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD HTML 4.01\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/strict.dtd">/;
196-
test.ok(regexp.test(document.outerHTML), 'HTML 4 strict doctype did not serialize correctly');
197+
test.ok(regexp.test(serializeDocument(document)), 'HTML 4 strict doctype did not serialize correctly');
197198
test.done();
198199
},
199200

@@ -202,7 +203,7 @@ exports.tests = {
202203
var doctype = dom.createDocumentType('foo', null, 'foo.dtd');
203204
var document = dom.createDocument(null, null, doctype);
204205
var regexp = /^\s*<!DOCTYPE foo SYSTEM "foo.dtd">/;
205-
test.ok(regexp.test(document.outerHTML), 'Doctype did not serialize correctly');
206+
test.ok(regexp.test(serializeDocument(document)), 'Doctype did not serialize correctly');
206207
test.done();
207208
},
208209

@@ -211,7 +212,7 @@ exports.tests = {
211212
var doctype = dom.createDocumentType('foo', null, 'foo "bar".dtd');
212213
var document = dom.createDocument(null, null, doctype);
213214
var regexp = /^\s*<!DOCTYPE foo SYSTEM \'foo "bar".dtd\'>/;
214-
test.ok(regexp.test(document.outerHTML), 'Doctype did not serialize correctly');
215+
test.ok(regexp.test(serializeDocument(document)), 'Doctype did not serialize correctly');
215216
test.done();
216217
},
217218

test/jsdom/env.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var http = require("http");
66
var fs = require("fs");
77
var toFileUrl = require("../util").toFileUrl(__dirname);
88

9+
var serializeDocument = require('../../lib/jsdom').serializeDocument;
10+
911
exports["with invalid arguments"] = function (t) {
1012
t.throws(function () { jsdom.env(); });
1113
t.throws(function () { jsdom.env({}); });
@@ -20,7 +22,7 @@ exports["explicit config.html, full document"] = function (t) {
2022
url: "http://example.com/",
2123
done: function (err, window) {
2224
t.ifError(err);
23-
t.equal(window.document.innerHTML, "<!DOCTYPE html><html><head><title>Hi</title></head><body>Hello</body></html>");
25+
t.equal(serializeDocument(window.document, { omitDoctype: true }), "<!DOCTYPE html><html><head><title>Hi</title></head><body>Hello</body></html>");
2426
t.equal(window.location.href, "http://example.com/");
2527
t.equal(window.location.origin, "http://example.com");
2628
t.done();
@@ -34,7 +36,7 @@ exports["explicit config.html, with overriden config.url"] = function (t) {
3436
url: "http://example.com/",
3537
done: function (err, window) {
3638
t.ifError(err);
37-
t.equal(window.document.innerHTML, "<html><head></head><body>Hello</body></html>");
39+
t.equal(serializeDocument(window.document, { omitDoctype: true }), "<html><head></head><body>Hello</body></html>");
3840
t.equal(window.location.href, "http://example.com/");
3941
t.equal(window.location.origin, "http://example.com");
4042
t.equal(window.location.search, "");
@@ -97,7 +99,7 @@ exports["explicit config.html, a string that is also a valid URL"] = function (t
9799
url: "http://example.com/",
98100
done: function (err, window) {
99101
t.ifError(err);
100-
t.equal(window.document.innerHTML, "<html><head></head><body>http://example.com/</body></html>");
102+
t.equal(serializeDocument(window.document, { omitDoctype: true }), "<html><head></head><body>http://example.com/</body></html>");
101103
t.equal(window.location.href, "http://example.com/");
102104
t.done();
103105
}
@@ -111,7 +113,7 @@ exports["explicit config.html, a string that is also a valid file"] = function (
111113
url: "http://example.com/",
112114
done: function (err, window) {
113115
t.ifError(err);
114-
t.equal(window.document.innerHTML, "<html><head></head><body>" + body + "</body></html>");
116+
t.equal(serializeDocument(window.document, { omitDoctype: true }), "<html><head></head><body>" + body + "</body></html>");
115117
t.equal(window.location.href, "http://example.com/");
116118
t.done();
117119
}
@@ -132,7 +134,7 @@ exports["explicit config.url, valid"] = function (t) {
132134
url: "http://localhost:8976/",
133135
done: function (err, window) {
134136
t.ifError(err);
135-
t.equal(window.document.innerHTML, responseText);
137+
t.equal(serializeDocument(window.document, { omitDoctype: true }), responseText);
136138
t.equal(window.location.href, "http://localhost:8976/");
137139
t.equal(window.location.origin, "http://localhost:8976");
138140
t.done();
@@ -158,7 +160,7 @@ exports["explicit config.file, valid"] = function (t) {
158160
file: fileName,
159161
done: function (err, window) {
160162
t.ifError(err);
161-
t.equal(window.document.innerHTML, '<!DOCTYPE html><html><head>\n\
163+
t.equal(serializeDocument(window.document, { omitDoctype: true }), '<!DOCTYPE html><html><head>\n\
162164
<title>hello, Node.js!</title>\n\
163165
</head>\n\
164166
<body>\n\
@@ -226,7 +228,7 @@ exports["string, parseable as a URL, valid"] = function (t) {
226228
"http://localhost:8976/",
227229
function (err, window) {
228230
t.ifError(err);
229-
t.equal(window.document.innerHTML, responseText);
231+
t.equal(serializeDocument(window.document, { omitDoctype: true }), responseText);
230232
t.equal(window.location.href, "http://localhost:8976/");
231233
t.equal(window.location.origin, "http://localhost:8976");
232234
t.done();
@@ -252,7 +254,7 @@ exports["string, for an existing filename"] = function (t) {
252254
fileName,
253255
function (err, window) {
254256
t.ifError(err);
255-
t.equal(window.document.innerHTML, '<!DOCTYPE html><html><head>\n\
257+
t.equal(serializeDocument(window.document, { omitDoctype: true }), '<!DOCTYPE html><html><head>\n\
256258
<title>hello, Node.js!</title>\n\
257259
</head>\n\
258260
<body>\n\
@@ -272,7 +274,7 @@ exports["string, does not exist as a file"] = function (t) {
272274
body,
273275
function (err, window) {
274276
t.ifError(err);
275-
t.equal(window.document.innerHTML, "<html><head></head><body>" + body + "</body></html>");
277+
t.equal(serializeDocument(window.document, { omitDoctype: true }), "<html><head></head><body>" + body + "</body></html>");
276278
t.done();
277279
}
278280
);
@@ -283,7 +285,7 @@ exports["string, full HTML document"] = function (t) {
283285
"<!DOCTYPE html><html><head><title>Hi</title></head><body>Hello</body></html>",
284286
function (err, window) {
285287
t.ifError(err);
286-
t.equal(window.document.innerHTML, "<!DOCTYPE html><html><head><title>Hi</title></head><body>Hello</body></html>");
288+
t.equal(serializeDocument(window.document, { omitDoctype: true }), "<!DOCTYPE html><html><head><title>Hi</title></head><body>Hello</body></html>");
287289
t.done();
288290
}
289291
);

test/jsdom/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var http = require("http");
77
var URL = require('url');
88
var um = require('urlmaster');
99

10+
var serializeDocument = require('../../lib/jsdom').serializeDocument;
11+
1012
function tmpWindow() {
1113
return jsdom.jsdom(null, { documentRoot: __dirname }).parentWindow;
1214
}
@@ -785,11 +787,11 @@ exports.tests = {
785787

786788
case_sensitivity_of_markup_missing_html_and_body : function(test){
787789
var spaces = /[ \n]*/g,
788-
doc1 = jsdom.jsdom("<HTML><BODY></BODY></HTML>").outerHTML.replace(spaces, ''),
789-
doc2 = jsdom.jsdom("<html><BODY></Body></HTML>").outerHTML.replace(spaces, ''),
790-
doc3 = jsdom.jsdom("<html><body></body></html>").outerHTML.replace(spaces, ''),
791-
doc4 = jsdom.jsdom("<body></body>").outerHTML.replace(spaces, ''),
792-
doc5 = jsdom.jsdom("").outerHTML.replace(spaces, '');
790+
doc1 = serializeDocument(jsdom.jsdom("<HTML><BODY></BODY></HTML>")).replace(spaces, ''),
791+
doc2 = serializeDocument(jsdom.jsdom("<html><BODY></Body></HTML>")).replace(spaces, ''),
792+
doc3 = serializeDocument(jsdom.jsdom("<html><body></body></html>")).replace(spaces, ''),
793+
doc4 = serializeDocument(jsdom.jsdom("<body></body>")).replace(spaces, ''),
794+
doc5 = serializeDocument(jsdom.jsdom("")).replace(spaces, '');
793795

794796
test.ok(doc1 === doc2 && doc2 == doc3 && doc3 === doc4 && doc4 == doc5,
795797
'they should all serialize the same');
@@ -799,7 +801,7 @@ exports.tests = {
799801
serialization_of_void_elements : function(test){
800802
var html = '<html><head></head><body><div><br><hr><audio><source></audio></div></body></html>',
801803
doc = jsdom.jsdom(html);
802-
test.strictEqual(doc.outerHTML, html)
804+
test.strictEqual(serializeDocument(doc), html)
803805
test.done();
804806
},
805807

@@ -978,7 +980,7 @@ exports.tests = {
978980
issues_230_259 : function(test) {
979981
var instr = '<html><body style="color: #ffffff; foo: bar"></body></html>';
980982
var doc = jsdom.jsdom(instr);
981-
test.ok(doc.outerHTML.match(/0: *color/) === null);
983+
test.ok(serializeDocument(doc).match(/0: *color/) === null);
982984
test.done();
983985
},
984986

@@ -1150,7 +1152,7 @@ exports.tests = {
11501152
var onclick = a.getAttribute('onclick');
11511153
test.notEqual(onclick, null);
11521154
test.equal(onclick, 'somefunction()');
1153-
test.ok(doc.innerHTML.indexOf('onclick') > -1);
1155+
test.ok(serializeDocument(doc).indexOf('onclick') > -1);
11541156
test.done();
11551157
},
11561158

@@ -1206,7 +1208,7 @@ exports.tests = {
12061208
jsdom.env({
12071209
html : '<script type="text/javascript">window.a = 1;/* remove me */ console.log("executed?")</script>',
12081210
done : function(errors, window) {
1209-
window.document.innerHTML = window.document.innerHTML.replace('/* remove me */','');
1211+
window.document.innerHTML = serializeDocument(window.document).replace('/* remove me */','');
12101212
test.equal(typeof window.a, 'undefined');
12111213
test.done();
12121214
}
@@ -1327,7 +1329,7 @@ exports.tests = {
13271329
issue_371_outerhtml_noformat : function(test) {
13281330
var originalHTML = '<li><span>A</span><span>B</span></li>';
13291331
var dom = jsdom.jsdom(originalHTML);
1330-
var outerHTML = dom.outerHTML;
1332+
var outerHTML = serializeDocument(dom);
13311333

13321334
test.equal(outerHTML, '<html><head></head><body>' + originalHTML + '</body></html>');
13331335
test.done();

test/window/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var serializeDocument = require('../../lib/jsdom').serializeDocument;
12
var dom = require("../../lib/jsdom/level1/core").dom.level1.core;
23

34
exports.tests = {
@@ -8,8 +9,8 @@ exports.tests = {
89
window.document.getElementsByTagName("head").item(0).appendChild(meta);
910
var elements = window.document.getElementsByTagName("head").item(0).childNodes;
1011
test.strictEqual(elements.item(elements.length-1), meta, 'last element should be the new meta tag');
11-
test.ok(window.document.innerHTML.indexOf("<meta>") > -1, 'meta should have open tag');
12-
test.strictEqual(window.document.innerHTML.indexOf("</meta>"), -1, 'meta should not be stringified with a closing tag');
12+
test.ok(serializeDocument(window.document).indexOf("<meta>") > -1, 'meta should have open tag');
13+
test.strictEqual(serializeDocument(window.document).indexOf("</meta>"), -1, 'meta should not be stringified with a closing tag');
1314
test.done();
1415
},
1516

0 commit comments

Comments
 (0)