selector.test.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. require("./chai.helper");
  2. var domHelper = require("./dom.helper");
  3. describe("attr", function () {
  4. beforeEach(function () {
  5. domHelper(
  6. "<div id=\"single1\">" +
  7. "<span>should not be selected when inside context</span>" +
  8. "</div>" +
  9. "<div id=\"single2\"></div>" +
  10. "<span>this should also not be selected</span>"
  11. );
  12. });
  13. it("should select a single element by ID", function () {
  14. var elt = $("#single1");
  15. elt.size().should.equal(1);
  16. elt.get(0).id.should.equal("single1");
  17. });
  18. it("should select multiple elements", function () {
  19. var elts = $("div");
  20. elts.size().should.equal(2);
  21. });
  22. it("should wrap native DOM elements", function () {
  23. var elt = document.createElement("div");
  24. $(elt).get(0).should.equal(elt);
  25. });
  26. it("should not wrap af objects more than once", function () {
  27. var elt = $("#single1").get(0);
  28. $($("#single1")).get(0).should.equal(elt);
  29. });
  30. it("should create elements", function () {
  31. var elt = $("<div id=\"foobar\"></div>").get(0);
  32. elt.id.should.equal("foobar");
  33. });
  34. it("should select within a context if supplied", function () {
  35. var text = "<div id=\"parent_test_cont\">" +
  36. "<div class=\"parent1\" id=\"parent1\">" +
  37. "<span class=\"parsel\">Foo</span>" +
  38. "<span class=\"parsel\">Foo</span>" +
  39. "</div>"+
  40. "<div class=\"parent1\" id=\"parent2\">" +
  41. "<span class=\"parsel\">Foo</span>" +
  42. "</div>" +
  43. "<div class=\"parent1\" id=\"parent3\">" +
  44. "<p class=\"parsel\">Foo</p>" +
  45. "</div>" +
  46. "<span class=\"parent1\" id=\"parent3\">" +
  47. "<p class=\"parsel\">Foo</p>" +
  48. "</span>" +
  49. "</div>";
  50. $("#single2").append(text);
  51. var tmp = $("#parent_test_cont");
  52. $("span", tmp).length.should.equal(4);
  53. });
  54. it("should remove spaces when constructing HTML", function () {
  55. $(" <div /> ").length.should.equal(1);
  56. });
  57. });