From 701cbb3daa309fc56fe7b026d66e94d882a0a2a2 Mon Sep 17 00:00:00 2001 From: Karuna Sagar Date: Sun, 6 Mar 2011 14:57:19 +0530 Subject: [PATCH] added test case to exercise NodeList#indexOf() --- test/browser/index.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/browser/index.js b/test/browser/index.js index 9c25757e09..7fe81e8a29 100644 --- a/test/browser/index.js +++ b/test/browser/index.js @@ -212,5 +212,44 @@ exports.tests = { var document = dom.createDocument(null, null, doctype); assertTrue('Doctype did not serialize correctly', /^\s*/.test(document.outerHTML)); + }, + basic_nodelist_indexOf : function() { + var doc = new browser.Document(); + + var html = doc.createElement("html"); + doc.appendChild(html); + + var body = doc.createElement("body"); + html.appendChild(body); + + var p = doc.createElement("p"); + body.appendChild(p); + + var div = doc.createElement("div"); + body.appendChild(div); + + var span = doc.createElement("span"); + body.appendChild(span); + + var index = body.childNodes.indexOf(span); + assertEquals("indexOf 'span' in childNodes", 2, index); + }, + nonexistant_nodelist_indexOf : function() { + var doc = new browser.Document(); + + var html = doc.createElement("html"); + doc.appendChild(html); + + var body = doc.createElement("body"); + html.appendChild(body); + + var p = doc.createElement("p"); + body.appendChild(p); + + var div = doc.createElement("div"); + p.appendChild(div); + + var index = body.childNodes.indexOf(div); + assertEquals("indexOf 'span' in childNodes", -1, index); } };