appendTo.test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require("./chai.helper");
  2. var domHelper = require("./dom.helper");
  3. describe("appendTo", function () {
  4. beforeEach(function () {
  5. domHelper(
  6. "<div id=\"appendToTest\"></div>"
  7. );
  8. });
  9. it("should append a string to an element", function () {
  10. $("<span class=\"important\"></span>").appendTo("#appendToTest");
  11. document.getElementById("appendToTest").childNodes.length.should.equal(1);
  12. });
  13. it("should append a DOM element", function () {
  14. var elt = document.createElement("p");
  15. elt.setAttribute("id", "intro");
  16. elt.textContent = "hello";
  17. $(elt).appendTo("#appendToTest");
  18. var children = document.getElementById("appendToTest").childNodes;
  19. children.length.should.equal(1);
  20. children[0].getAttribute("id").should.equal("intro");
  21. children[0].textContent.should.equal("hello");
  22. });
  23. it("should append multiple DOM elements in the correct order", function () {
  24. var elt1 = document.createElement("p");
  25. elt1.setAttribute("id", "end");
  26. elt1.textContent = "world";
  27. var elt2 = document.createElement("p");
  28. elt2.setAttribute("id", "more-end");
  29. elt2.textContent = "goodbye";
  30. $(elt1).appendTo("#appendToTest");
  31. $(elt2).appendTo("#appendToTest");
  32. var children = document.getElementById("appendToTest").childNodes;
  33. children.length.should.equal(2);
  34. children[1].getAttribute("id").should.equal("more-end");
  35. children[1].textContent.should.equal("goodbye");
  36. });
  37. });