Created
November 7, 2011 16:17
-
-
Save leviwilson/1345408 to your computer and use it in GitHub Desktop.
Jasmine Spy Misuse
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
describe('Backbone View Example', function () { | |
beforeEach(function () { | |
this.collection = jasmine.createSpyObj(MyModels, ['bind']); | |
this.view = new MyView({collection: this.collection}); | |
}); | |
it('should render itself when the collection changes', function () { | |
expect(this.collection.bind) | |
.toHaveBeenCalledWith(['change', this.view.render]); | |
}); | |
it('should render itself when the collection changes v2', function () { | |
var args = this.collection.bind.mostRecentCall.args; | |
expect(args[0]).toEqual('change'); | |
expect(args[1]).toEqual(this.view.render); | |
}); | |
}); |
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
(function($) { | |
MyModel = Backbone.Model.extend({}); | |
MyModels = Backbone.Collection.extend({ | |
model: MyModel | |
}); | |
MyView = Backbone.View.extend({ | |
initialize: function () { | |
_.bindAll(this, 'render'); | |
this.collection.bind('change', this.render); | |
}, | |
render: function () { | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment