Created
October 24, 2012 10:48
-
-
Save lennym/3945437 to your computer and use it in GitHub Desktop.
Spying on bound methods
This file contains hidden or 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('A hypothetical situation', function () { | |
| var View = Backbone.View.extend({ | |
| initialize: function () { | |
| this.model = new Backbone.Model; | |
| this.model.on('change', this.render, this); | |
| } | |
| }), instance; | |
| beforeEach(function () { | |
| instance = new View(); | |
| }); | |
| it('view renders on model change', function () { | |
| spyOn(instance, 'render'); | |
| instance.model.trigger('change'); | |
| expect(instance.render).toHaveBeenCalled(); // fails | |
| }); | |
| }); |
Author
That still fails. Changing the event binding to:
this.model.on('change', function () { this.render(); }, this);
works, but is ugly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Spy on the prototype of the view instead: