ParentNode-append.html (3097B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>ParentNode.append</title> 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-parentnode-append"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="pre-insertion-validation-hierarchy.js"></script> 8 <script> 9 preInsertionValidateHierarchy("append"); 10 11 function test_append(node, nodeName) { 12 test(function() { 13 const parent = node.cloneNode(); 14 parent.append(); 15 assert_array_equals(parent.childNodes, []); 16 }, nodeName + '.append() without any argument, on a parent having no child.'); 17 18 test(function() { 19 const parent = node.cloneNode(); 20 parent.append(null); 21 assert_equals(parent.childNodes[0].textContent, 'null'); 22 }, nodeName + '.append() with null as an argument, on a parent having no child.'); 23 24 test(function() { 25 const parent = node.cloneNode(); 26 parent.append(undefined); 27 assert_equals(parent.childNodes[0].textContent, 'undefined'); 28 }, nodeName + '.append() with undefined as an argument, on a parent having no child.'); 29 30 test(function() { 31 const parent = node.cloneNode(); 32 parent.append('text'); 33 assert_equals(parent.childNodes[0].textContent, 'text'); 34 }, nodeName + '.append() with only text as an argument, on a parent having no child.'); 35 36 test(function() { 37 const parent = node.cloneNode(); 38 const x = document.createElement('x'); 39 parent.append(x); 40 assert_array_equals(parent.childNodes, [x]); 41 }, nodeName + '.append() with only one element as an argument, on a parent having no child.'); 42 43 test(function() { 44 const parent = node.cloneNode(); 45 const child = document.createElement('test'); 46 parent.appendChild(child); 47 parent.append(null); 48 assert_equals(parent.childNodes[0], child); 49 assert_equals(parent.childNodes[1].textContent, 'null'); 50 }, nodeName + '.append() with null as an argument, on a parent having a child.'); 51 52 test(function() { 53 const parent = node.cloneNode(); 54 const x = document.createElement('x'); 55 const child = document.createElement('test'); 56 parent.appendChild(child); 57 parent.append(x, 'text'); 58 assert_equals(parent.childNodes[0], child); 59 assert_equals(parent.childNodes[1], x); 60 assert_equals(parent.childNodes[2].textContent, 'text'); 61 }, nodeName + '.append() with one element and text as argument, on a parent having a child.'); 62 63 test(function() { 64 const parent = node.cloneNode(); 65 const x = document.createElement('x'); 66 const y = document.createElement('y'); 67 parent.append(x, y, x); 68 assert_equals(parent.childNodes.length, 2); 69 assert_equals(parent.childNodes[0], y); 70 assert_equals(parent.childNodes[1], x); 71 }, nodeName + '.append() with the same element twice.'); 72 } 73 74 test_append(document.createElement('div'), 'Element'); 75 test_append(document.createDocumentFragment(), 'DocumentFragment'); 76 </script> 77 </html>