OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <meta charset=utf-8> | |
3 <title>ParentNode.prepend</title> | |
4 <link rel=help href="https://dom.spec.whatwg.org/#dom-parentnode-prepend"> | |
5 <script src="../../../../resources/testharness.js"></script> | |
6 <script src="../../../../resources/testharnessreport.js"></script> | |
7 <script> | |
8 | |
9 function test_prepend(node, nodeName) { | |
10 | |
11 test(function() { | |
12 var parent = node.cloneNode(); | |
13 parent.prepend(); | |
14 assert_array_equals(parent.childNodes, []); | |
15 }, nodeName + '.prepend() without any argument, on a parent having no child.
'); | |
16 | |
17 test(function() { | |
18 var parent = node.cloneNode(); | |
19 parent.prepend(null); | |
20 assert_equals(parent.childNodes[0].textContent, 'null'); | |
21 }, nodeName + '.prepend() with null as an argument, on a parent having no ch
ild.'); | |
22 | |
23 test(function() { | |
24 var parent = node.cloneNode(); | |
25 parent.prepend(undefined); | |
26 assert_equals(parent.childNodes[0].textContent, 'undefined'); | |
27 }, nodeName + '.prepend() with undefined as an argument, on a parent having
no child.'); | |
28 | |
29 test(function() { | |
30 var parent = node.cloneNode(); | |
31 parent.prepend('text'); | |
32 assert_equals(parent.childNodes[0].textContent, 'text'); | |
33 }, nodeName + '.prepend() with only text as an argument, on a parent having
no child.'); | |
34 | |
35 test(function() { | |
36 var parent = node.cloneNode(); | |
37 var x = document.createElement('x'); | |
38 parent.prepend(x); | |
39 assert_array_equals(parent.childNodes, [x]); | |
40 }, nodeName + '.prepend() with only one element as an argument, on a parent
having no child.'); | |
41 | |
42 test(function() { | |
43 var parent = node.cloneNode(); | |
44 var child = document.createElement('test'); | |
45 parent.appendChild(child); | |
46 parent.prepend(null); | |
47 assert_equals(parent.childNodes[0].textContent, 'null'); | |
48 assert_equals(parent.childNodes[1], child); | |
49 }, nodeName + '.prepend() with null as an argument, on a parent having a chi
ld.'); | |
50 | |
51 test(function() { | |
52 var parent = node.cloneNode(); | |
53 var x = document.createElement('x'); | |
54 var child = document.createElement('test'); | |
55 parent.appendChild(child); | |
56 parent.prepend(x, 'text'); | |
57 assert_equals(parent.childNodes[0], x); | |
58 assert_equals(parent.childNodes[1].textContent, 'text'); | |
59 assert_equals(parent.childNodes[2], child); | |
60 }, nodeName + '.prepend() with one element and text as argument, on a parent
having a child.'); | |
61 } | |
62 | |
63 test_prepend(document.createElement('div'), 'Element'); | |
64 test_prepend(document.createDocumentFragment(), 'DocumentFrgment'); | |
65 </script> | |
66 </html> | |
OLD | NEW |