Skip to content

Commit

Permalink
test for undelegate with handler and selector, and use an element tha…
Browse files Browse the repository at this point in the history
…t exists in the DOM for bubbling
  • Loading branch information
akre54 committed Mar 12, 2014
1 parent d21fd79 commit d99e43b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
});

test("undelegate", 0, function() {
view = new Backbone.View({el: '#testElement'});
view.delegate('click', function() { ok(false); });
view.delegate('click', 'h1', function() { ok(false); });

Expand All @@ -155,6 +156,7 @@
})

test("undelegate with passed handler", 1, function() {
view = new Backbone.View({el: '#testElement'});
var listener = view.delegate('click', function() { ok(false); });
view.delegate('click', function() { ok(true); });
view.undelegate('click', listener);
Expand All @@ -163,6 +165,7 @@

test("undelegate with selector", 2, function() {
var counter1 = 0, counter2 = 0;
view = new Backbone.View({el: '#testElement'});
view.delegate('click', function() { counter1++; });
view.delegate('click', 'h1', function() { counter2++; });

Expand All @@ -171,7 +174,22 @@
view.$('h1').trigger('click');
view.$el.trigger('click');

equal(counter1, 1);
equal(counter1, 2);
equal(counter2, 0);
});

test("undelegate with handler and selector", 2, function() {
var counter1 = 0, counter2 = 0;
view = new Backbone.View({el: '#testElement'});
view.delegate('click', function() { counter1++; });
var handler = view.delegate('click', 'h1', function() { counter2++; });

view.undelegate('click', 'h1', handler);

view.$('h1').trigger('click');
view.$el.trigger('click');

equal(counter1, 2);
equal(counter2, 0);
});

Expand Down

0 comments on commit d99e43b

Please sign in to comment.