bootstrap-switch.tests.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. (function() {
  2. describe("Bootstrap Switch", function() {
  3. var createElement, getOptions;
  4. beforeEach(function() {
  5. $.support.transition = false;
  6. return $.fx.off = true;
  7. });
  8. afterEach(function() {
  9. return $("." + $.fn.bootstrapSwitch.defaults.baseClass).bootstrapSwitch("destroy");
  10. });
  11. createElement = function() {
  12. return $("<input>", {
  13. type: "checkbox",
  14. "class": "switch"
  15. }).appendTo("body");
  16. };
  17. getOptions = function($element) {
  18. return $element.data("bootstrap-switch").options;
  19. };
  20. it("should set the default options as element options, except state", function() {
  21. var $switch;
  22. $switch = createElement().prop("checked", true).bootstrapSwitch();
  23. return expect(getOptions($switch)).toEqual($.fn.bootstrapSwitch.defaults);
  24. });
  25. return it("should override default options with initialization ones", function() {
  26. var $switch, $switch2;
  27. $switch = createElement().prop("checked", false).bootstrapSwitch();
  28. $switch2 = createElement().bootstrapSwitch({
  29. state: false
  30. });
  31. expect(getOptions($switch).state).toBe(false);
  32. return expect(getOptions($switch2).state).toBe(false);
  33. });
  34. });
  35. }).call(this);