Skip to content

Commit

Permalink
Test both _listeningTo and _events are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell authored and akre54 committed Nov 3, 2014
1 parent 55bdc3f commit b3ab611
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,22 @@
e.trigger("foo");
});

test("stopListening cleans up references", 4, function() {
test("stopListening cleans up references", 8, function() {
var a = _.extend({}, Backbone.Events);
var b = _.extend({}, Backbone.Events);
var fn = function() {};
a.listenTo(b, 'all', fn).stopListening();
a.listenTo(b, 'event', fn).stopListening();
equal(_.size(a._listeningTo), 0);
a.listenTo(b, 'all', fn).stopListening(b);
equal(_.size(b._events), 0);
a.listenTo(b, 'event', fn).stopListening(b);
equal(_.size(a._listeningTo), 0);
a.listenTo(b, 'all', fn).stopListening(null, 'all');
equal(_.size(b._events), 0);
a.listenTo(b, 'event', fn).stopListening(b, 'event');
equal(_.size(a._listeningTo), 0);
a.listenTo(b, 'all', fn).stopListening(null, null, fn);
equal(_.size(b._events), 0);
a.listenTo(b, 'event', fn).stopListening(b, 'event', fn);
equal(_.size(a._listeningTo), 0);
equal(_.size(b._events), 0);
});

test("listenTo and stopListening cleaning up references", 2, function() {
Expand Down Expand Up @@ -196,6 +200,24 @@
equal(_.keys(a._listeningTo).length, 1);
});

test("listenToOnce, stopListening cleans up references", 8, function() {
var a = _.extend({}, Backbone.Events);
var b = _.extend({}, Backbone.Events);
var fn = function() {};
a.listenToOnce(b, 'event', fn).stopListening();
equal(_.size(a._listeningTo), 0);
equal(_.size(b._events), 0);
a.listenToOnce(b, 'event', fn).stopListening(b);
equal(_.size(a._listeningTo), 0);
equal(_.size(b._events), 0);
a.listenToOnce(b, 'event', fn).stopListening(b, 'event');
equal(_.size(a._listeningTo), 0);
equal(_.size(b._events), 0);
a.listenToOnce(b, 'event', fn).stopListening(b, 'event', fn);
equal(_.size(a._listeningTo), 0);
equal(_.size(b._events), 0);
});

test("listenTo with empty callback doesn't throw an error", 1, function(){
var e = _.extend({}, Backbone.Events);
e.listenTo(e, "foo", null);
Expand Down

0 comments on commit b3ab611

Please sign in to comment.