Having problems spying method calls on a Backbone Router to ensure it calles the right method on a given route.
excerpt from the test
describe \'Router\'
I'm pretty sure this has to do with the way that Backbone binds to its routing methods when you use a routes hash (especially if you're seeing a console log correctly output). That is, the router has bound to the original index
method, but your spy has replaced the "current" index
method.
You have two options:
spyOn(@router, "index")
before you the router binds to the routes (may be difficult)index
method: spyOn(App.router.prototype, "index"); @router.navigate('', true); expect(App.router.prototype.index).toHaveBeenCalled();