clone.test.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. require("./chai.helper");
  2. var domHelper = require("./dom.helper");
  3. describe("clone", function () {
  4. beforeEach(function () {
  5. domHelper(
  6. "<div id=\"foo\">" +
  7. "<div id=\"bar\"></div><div id=\"mux\"></div>" +
  8. "</div>" +
  9. "<div id=\"blu\" class=\"red\"></div>" +
  10. "<div id=\"rd\" class=\"red\"></div>"
  11. );
  12. });
  13. it("should shallow clone with no children", function () {
  14. var cloned = $("#foo").clone(false).get(0);
  15. cloned.childNodes.length.should.equal(0);
  16. cloned.id.should.equal(document.getElementById("foo").id);
  17. });
  18. it("should deep clone including children", function () {
  19. var original = document.getElementById("foo");
  20. var cloned = $("#foo").clone(true).get(0);
  21. cloned.childNodes.length.should.equal(original.childNodes.length);
  22. cloned.id.should.equal(original.id);
  23. });
  24. it("should clone multiple elements in a collection", function () {
  25. var originals = document.querySelectorAll(".red");
  26. var clones = $(".red").clone();
  27. clones.length.should.equal(originals.length);
  28. for (var i = 0; i < clones.length; i += 1) {
  29. clones[i].id.should.equal(originals[i].id);
  30. }
  31. });
  32. });