Skip to content

Commit

Permalink
Add tests for appendTo()
Browse files Browse the repository at this point in the history
  • Loading branch information
townxelliot committed Aug 27, 2013
1 parent c60f94b commit a91f5a5
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/appendTo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require("./chai.helper");
var domHelper = require("./dom.helper");

describe("appendTo", function () {
beforeEach(function () {
domHelper(
"<div id=\"appendToTest\"></div>"
);
});

it("should append a string to an element", function () {
$("<span class=\"important\"></span>").appendTo("#appendToTest");
document.getElementById("appendToTest").childNodes.length.should.equal(1);
});

it("should append a DOM element", function () {
var elt = document.createElement("p");
elt.setAttribute("id", "intro");
elt.textContent = "hello";

$(elt).appendTo("#appendToTest");

var children = document.getElementById("appendToTest").childNodes;
children.length.should.equal(1);
children[0].getAttribute("id").should.equal("intro");
children[0].textContent.should.equal("hello");
});

it("should append multiple DOM elements in the correct order", function () {
var elt1 = document.createElement("p");
elt1.setAttribute("id", "end");
elt1.textContent = "world";

var elt2 = document.createElement("p");
elt2.setAttribute("id", "more-end");
elt2.textContent = "goodbye";

$(elt1).appendTo("#appendToTest");
$(elt2).appendTo("#appendToTest");

var children = document.getElementById("appendToTest").childNodes;
children.length.should.equal(2);
children[1].getAttribute("id").should.equal("more-end");
children[1].textContent.should.equal("goodbye");
});
});

0 comments on commit a91f5a5

Please sign in to comment.