OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <meta charset=utf-8> | |
3 <title>ChildNode.replaceWith</title> | |
4 <link rel=help href="https://dom.spec.whatwg.org/#dom-childnode-replaceWith"> | |
5 <script src="../../../../resources/testharness.js"></script> | |
6 <script src="../../../../resources/testharnessreport.js"></script> | |
7 <script> | |
8 | |
9 function test_replaceWith(child, nodeName, innerHTML) { | |
10 | |
11 test(function() { | |
12 var parent = document.createElement('div'); | |
13 parent.appendChild(child); | |
14 child.replaceWith(); | |
15 assert_equals(parent.innerHTML, ''); | |
16 }, nodeName + '.replaceWith() without any argument.'); | |
17 | |
18 test(function() { | |
19 var parent = document.createElement('div'); | |
20 parent.appendChild(child); | |
21 child.replaceWith(null); | |
22 assert_equals(parent.innerHTML, 'null'); | |
23 }, nodeName + '.replaceWith() with null as an argument.'); | |
24 | |
25 test(function() { | |
26 var parent = document.createElement('div'); | |
27 parent.appendChild(child); | |
28 child.replaceWith(undefined); | |
29 assert_equals(parent.innerHTML, 'undefined'); | |
30 }, nodeName + '.replaceWith() with undefined as an argument.'); | |
31 | |
32 test(function() { | |
33 var parent = document.createElement('div'); | |
34 parent.appendChild(child); | |
35 child.replaceWith(''); | |
36 assert_equals(parent.innerHTML, ''); | |
37 }, nodeName + '.replaceWith() with empty string as an argument.'); | |
38 | |
39 test(function() { | |
40 var parent = document.createElement('div'); | |
41 parent.appendChild(child); | |
42 child.replaceWith('text'); | |
43 assert_equals(parent.innerHTML, 'text'); | |
44 }, nodeName + '.replaceWith() with only text as an argument.'); | |
45 | |
46 test(function() { | |
47 var parent = document.createElement('div'); | |
48 var x = document.createElement('x'); | |
49 parent.appendChild(child); | |
50 child.replaceWith(x); | |
51 assert_equals(parent.innerHTML, '<x></x>'); | |
52 }, nodeName + '.replaceWith() with only one element as an argument.'); | |
53 | |
54 test(function() { | |
55 var parent = document.createElement('div'); | |
56 var x = document.createElement('x'); | |
57 var y = document.createElement('y'); | |
58 var z = document.createElement('z'); | |
59 parent.appendChild(y); | |
60 parent.appendChild(child); | |
61 parent.appendChild(x); | |
62 child.replaceWith(x, y, z); | |
63 assert_equals(parent.innerHTML, '<x></x><y></y><z></z>'); | |
64 }, nodeName + '.replaceWith() with sibling of child as arguments.'); | |
65 | |
66 test(function() { | |
67 var parent = document.createElement('div'); | |
68 var x = document.createElement('x'); | |
69 parent.appendChild(child); | |
70 parent.appendChild(x); | |
71 parent.appendChild(document.createTextNode('1')); | |
72 child.replaceWith(x, '2'); | |
73 assert_equals(parent.innerHTML, '<x></x>21'); | |
74 }, nodeName + '.replaceWith() with one sibling of child and text as argument
s.'); | |
75 | |
76 test(function() { | |
77 var parent = document.createElement('div'); | |
78 var x = document.createElement('x'); | |
79 parent.appendChild(child); | |
80 parent.appendChild(x); | |
81 parent.appendChild(document.createTextNode('text')); | |
82 child.replaceWith(x, child); | |
83 assert_equals(parent.innerHTML, '<x></x>' + innerHTML + 'text'); | |
84 }, nodeName + '.replaceWith() with one sibling of child and child itself as
arguments.'); | |
85 | |
86 test(function() { | |
87 var parent = document.createElement('div'); | |
88 var x = document.createElement('x'); | |
89 parent.appendChild(child); | |
90 child.replaceWith(x, 'text'); | |
91 assert_equals(parent.innerHTML, '<x></x>text'); | |
92 }, nodeName + '.replaceWith() with one element and text as arguments.'); | |
93 | |
94 test(function() { | |
95 var parent = document.createElement('div'); | |
96 var x = document.createElement('x'); | |
97 var y = document.createElement('y'); | |
98 parent.appendChild(x); | |
99 parent.appendChild(y); | |
100 child.replaceWith(x, y); | |
101 assert_equals(parent.innerHTML, '<x></x><y></y>'); | |
102 }, nodeName + '.replaceWith() on a parentless child with two elements as arg
uments.'); | |
103 } | |
104 | |
105 test_replaceWith(document.createComment('test'), 'Comment', '<!--test-->'); | |
106 test_replaceWith(document.createElement('test'), 'Element', '<test></test>'); | |
107 test_replaceWith(document.createTextNode('test'), 'Text', 'test'); | |
108 | |
109 </script> | |
110 </html> | |
OLD | NEW |