Browse Source

added a test that checks that the events are fired correctly

Mattia Larentis 10 years ago
parent
commit
5cad1cd245
2 changed files with 29 additions and 5 deletions
  1. 15 5
      src/coffee/bootstrap-switch.tests.coffee
  2. 14 0
      test/bootstrap-switch.tests.js

+ 15 - 5
src/coffee/bootstrap-switch.tests.coffee

@@ -33,6 +33,21 @@ describe "Bootstrap Switch:", ->
     expect(getOptions($switch).state).toBe false
     expect(getOptions($switch2).state).toBe false
 
+  it "should something", ->
+    eventDoc = eventElement = 0
+    $switch = createCheckbox().bootstrapSwitch()
+
+    $(document).on "switchChange.bootstrapSwitch", ":checkbox", (event, state) ->
+      eventDoc++
+
+    $(":checkbox").on "switchChange.bootstrapSwitch", (event, state) ->
+      eventElement++
+
+    $switch.click()
+
+    expect(eventElement).toEqual eventDoc
+    expect(eventElement).toEqual 1
+
   describe "The Checkbox Bootstrap Switch", ->
     it "should conserve its state if onSwitchChange returns false", ->
       $switch = createCheckbox().bootstrapSwitch
@@ -88,8 +103,3 @@ describe "Bootstrap Switch:", ->
       expect($radio1.bootstrapSwitch('state')).toEqual false
       expect($radio2.bootstrapSwitch('state')).toEqual true
       expect($radio3.bootstrapSwitch('state')).toEqual false
-
-
-
-
-

+ 14 - 0
test/bootstrap-switch.tests.js

@@ -38,6 +38,20 @@
       expect(getOptions($switch).state).toBe(false);
       return expect(getOptions($switch2).state).toBe(false);
     });
+    it("should something", function() {
+      var $switch, eventDoc, eventElement;
+      eventDoc = eventElement = 0;
+      $switch = createCheckbox().bootstrapSwitch();
+      $(document).on("switchChange.bootstrapSwitch", ":checkbox", function(event, state) {
+        return eventDoc++;
+      });
+      $(":checkbox").on("switchChange.bootstrapSwitch", function(event, state) {
+        return eventElement++;
+      });
+      $switch.click();
+      expect(eventElement).toEqual(eventDoc);
+      return expect(eventElement).toEqual(1);
+    });
     describe("The Checkbox Bootstrap Switch", function() {
       it("should conserve its state if onSwitchChange returns false", function() {
         var $indeterminateSwitch, $switch;