Repository navigation
Expand file tree
/
Copy pathdomparsing.js
More file actions
75 lines (54 loc) · 2.39 KB
/
Copy pathdomparsing.js
File metadata and controls
75 lines (54 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"use strict";
const jsdom = require("../..");
const domExceptionPredicate = require("../util").domExceptionPredicate;
// http://www.w3.org/TR/DOM-Parsing/
// (which is referenced by http://html.spec.whatwg.org/ )
exports["Setting outerHTML on the documentElement is not allowed"] = t => {
const doc = jsdom.jsdom("<html/>");
t.throws(() => {
doc.documentElement.outerHTML = "<html><head><title></title></head><body></body></html>";
}, domExceptionPredicate(doc, "NoModificationAllowedError"));
t.done();
};
exports["Setting outerHTML on an Element without a parent should have no effect"] = t => {
const doc = jsdom.jsdom("<html/>");
const element = doc.createElement("div");
element.textContent = "foo";
element.outerHTML = "<p>bar</p>";
t.strictEqual(element.outerHTML, "<div>foo</div>");
t.done();
};
exports["Setting outerHTML on an Element"] = t => {
const doc = jsdom.jsdom("<html><head></head><body>foo<p>bar</p></body></html>");
const newHtml = "<b>az</b>";
const oldElement = doc.body.children[0];
oldElement.outerHTML = newHtml;
t.strictEqual(oldElement.outerHTML, "<p>bar</p>");
t.strictEqual(doc.body.children[0].outerHTML, newHtml);
t.done();
};
exports["Setting outerHTML on <body>"] = t => {
const doc = jsdom.jsdom("<html><head></head><body>foo<p>bar</p></body></html>");
const newHtml = "<body><h1>Hysterocrates crassipes</h1>" +
"<p>spinnensoort in de taxonomische indeling van de vogelspinnen</p></body>";
const oldBody = doc.body;
oldBody.outerHTML = newHtml;
t.strictEqual(oldBody.outerHTML, "<body>foo<p>bar</p></body>");
t.strictEqual(doc.body.outerHTML, newHtml);
t.done();
};
exports["Setting outerHTML on an Element with a DocumentFragment as parent"] = t => {
const doc = jsdom.jsdom();
const fragment = doc.createDocumentFragment();
const oldElement = doc.createElement("div");
fragment.appendChild(oldElement);
oldElement.innerHTML = "foo<p>bar</p>";
const newHtml = "<div><h1>Hysterocrates crassipes</h1>" +
"<p>spinnensoort in de taxonomische indeling van de vogelspinnen</p></div>";
// the <body> element should not be included
// (because the context node will be a temporary <body> element)
oldElement.outerHTML = "<body>" + newHtml + "</body>";
t.strictEqual(oldElement.outerHTML, "<div>foo<p>bar</p></div>");
t.strictEqual(fragment.firstChild.outerHTML, newHtml);
t.done();
};