1 var DomUtils = require("../..");
2 var fixture = require("../fixture");
3 var assert = require("assert");
5 // Set up expected structures
11 for (var idx = 0; idx < 20; ++idx) {
12 expected.tag2.push(fixture[idx*2 + 1].children[5]);
13 expected.typeScript.push(fixture[idx*2 + 1].children[1]);
16 describe("legacy", function() {
17 describe("getElements", function() {
18 var getElements = DomUtils.getElements;
19 it("returns the node with the specified ID", function() {
21 getElements({ id: "asdf" }, fixture, true, 1),
25 it("returns empty array for unknown IDs", function() {
26 assert.deepEqual(getElements({ id: "asdfs" }, fixture, true), []);
28 it("returns the nodes with the specified tag name", function() {
30 getElements({ tag_name:"tag2" }, fixture, true),
34 it("returns empty array for unknown tag names", function() {
36 getElements({ tag_name : "asdfs" }, fixture, true),
40 it("returns the nodes with the specified tag type", function() {
42 getElements({ tag_type: "script" }, fixture, true),
46 it("returns empty array for unknown tag types", function() {
48 getElements({ tag_type: "video" }, fixture, true),
54 describe("getElementById", function() {
55 var getElementById = DomUtils.getElementById;
56 it("returns the specified node", function() {
59 getElementById("asdf", fixture, true)
62 it("returns `null` for unknown IDs", function() {
63 assert.equal(null, getElementById("asdfs", fixture, true));
67 describe("getElementsByTagName", function() {
68 var getElementsByTagName = DomUtils.getElementsByTagName;
69 it("returns the specified nodes", function() {
71 getElementsByTagName("tag2", fixture, true),
75 it("returns empty array for unknown tag names", function() {
77 getElementsByTagName("tag23", fixture, true),
83 describe("getElementsByTagType", function() {
84 var getElementsByTagType = DomUtils.getElementsByTagType;
85 it("returns the specified nodes", function() {
87 getElementsByTagType("script", fixture, true),
91 it("returns empty array for unknown tag types", function() {
93 getElementsByTagType("video", fixture, true),
99 describe("getOuterHTML", function() {
100 var getOuterHTML = DomUtils.getOuterHTML;
101 it("Correctly renders the outer HTML", function() {
103 getOuterHTML(fixture[1]),
104 "<tag1 id=\"asdf\"> <script>text</script> <!-- comment --> <tag2> text </tag2></tag1>"
109 describe("getInnerHTML", function() {
110 var getInnerHTML = DomUtils.getInnerHTML;
111 it("Correctly renders the inner HTML", function() {
113 getInnerHTML(fixture[1]),
114 " <script>text</script> <!-- comment --> <tag2> text </tag2>"