OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <script src="../../../resources/testharness.js"></script> | |
3 <script src="../../../resources/testharnessreport.js"></script> | |
4 <script> | |
5 | |
6 function test_replaceWith(node, nodeName) { | |
7 var child; | |
8 var innerHTML; | |
9 if (nodeName == 'Comment') { | |
10 child = document.createComment('test'); | |
11 innerHTML = '<!--test-->'; | |
12 } else if (nodeName == 'Element') { | |
13 child = document.createElement('test'); | |
14 innerHTML = '<test></test>'; | |
15 } else { | |
16 child = document.createTextNode('test'); | |
17 innerHTML = 'test'; | |
18 } | |
19 | |
20 test(function() { | |
21 var parent = node.cloneNode(); | |
22 parent.appendChild(child); | |
23 child.replaceWith(); | |
24 expected = ""; | |
philipj_slow
2015/06/15 10:06:58
Hmm, I think you can just fold the expected bit in
| |
25 assert_equals(parent.innerHTML, expected); | |
26 }, nodeName + '.replaceWith() without any argument.'); | |
philipj_slow
2015/06/15 10:06:58
Also need to test child.replaceWith(something) whe
| |
27 | |
28 test(function() { | |
29 var parent = node.cloneNode(); | |
30 parent.appendChild(child); | |
31 child.replaceWith(null); | |
32 expected = 'null'; | |
33 assert_equals(parent.innerHTML, expected); | |
34 }, nodeName + '.replaceWith() with null as an argument.'); | |
35 | |
36 test(function() { | |
37 var parent = node.cloneNode(); | |
38 parent.appendChild(child); | |
39 child.replaceWith('text'); | |
40 expected = 'text'; | |
41 assert_equals(parent.innerHTML, expected); | |
42 }, nodeName + '.replaceWith() with only text as an argument.'); | |
43 | |
44 test(function() { | |
45 var parent = node.cloneNode(); | |
46 var x = document.createElement('x'); | |
47 parent.appendChild(child); | |
48 child.replaceWith(x); | |
49 expected = '<x></x>'; | |
50 assert_equals(parent.innerHTML, expected); | |
51 }, nodeName + '.replaceWith() with only one element as an argument.'); | |
52 | |
53 test(function() { | |
54 var parent = node.cloneNode(); | |
55 var x = document.createElement('x'); | |
56 parent.appendChild(child); | |
57 child.replaceWith(x, 'text'); | |
58 expected = '<x></x>text'; | |
59 assert_equals(parent.innerHTML, expected); | |
60 }, nodeName + '.replaceWith() with one element and text as arguments.'); | |
61 } | |
62 | |
63 test_replaceWith(document.createElement('div'), 'Comment'); | |
64 test_replaceWith(document.createElement('div'), 'Element'); | |
65 test_replaceWith(document.createElement('div'), 'Text'); | |
66 | |
67 </script> | |
68 </html> | |
OLD | NEW |