The problem is that you bind the handle_click
function in the constructor. So when you create a new instance a reference to the function is binded to the event. After that you replace the foo.handle_click
with a spy. But this will not effect the function that was binded to the event as this is still your original function. You have to spy on the Foo.prototype.handle_click
function before you create the instance, so the spied function can be bound to the event.
it('should be called when trigger is clicked', function() {
spyOn( Foo.prototype, 'handle_click' );
var foo = new Foo();
foo.$btn.click();
expect( foo.handle_click ).toHaveBeenCalled();
});