Created
February 13, 2014 11:01
-
-
Save gabeno/8973233 to your computer and use it in GitHub Desktop.
remove callback bug in backbone?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var chai = require('chai'), | |
expect = chai.expect, | |
sinon = require('sinon'), | |
sinonChai = require('sinon-chai'); | |
var Backbone = require('backbone'); | |
var _ = require('lodash/dist/lodash.underscore'); | |
chai.use(sinonChai); | |
describe('Backbone.Events', function() { | |
var myObj; | |
beforeEach(function() { | |
myObj = {}; | |
_.extend(myObj, Backbone.Events); | |
}); | |
it('can remove custom events from objects', function() { | |
var spy1 = sinon.spy(); | |
var spy2 = sinon.spy(); | |
var spy3 = sinon.spy(); | |
myObj.on('foo', spy1); | |
myObj.on('bar', spy1); | |
myObj.on('foo', spy2); | |
myObj.on('foo', spy3); | |
// unbind a single callback for the event | |
myObj.off('foo', spy1); | |
myObj.trigger('foo'); | |
expect(spy1).to.have.callCount(0); | |
expect(spy2).to.have.callCount(1); | |
expect(spy3).to.have.callCount(1); | |
// remove all 'foo' callbacks | |
myObj.off('foo'); | |
myObj.trigger('foo'); | |
expect(spy1).to.have.callCount(0); | |
expect(spy2).to.have.callCount(0); // spy called once, why?? | |
expect(spy3).to.have.callCount(0); // spy called once, why?? | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How come
spy2
andspy3
are still around even after unbinding them fromfoo
event?