The call to App.vent.on
in your initialize
function passes a reference to the view instance's this.updateDVR
function -- and that happens right before you spyOn(this.showDvr, ...)
in the test's beforeEach
. So when you trigger the event, the trigger calls that retained reference to the actual updateDVR
function, not the spy.
You should be able to fix it by passing a callback function to the App.vent.on
call, like so (sorry for the javascript, I'm not a coffeescripter!):
initialize: function () {
var that = this;
// hold onto the callback so we can unregister it in App.vent.off, too
this.onUpdateCb = function() { that.updateDVR() };
App.vent.on("deciseconds:updated", this.onUpdateCb );
// if this is a view, stop listening for App.vent when the view closes
this.listenTo(this, 'close', function() { App.vent.off("deciseconds:updated", this.onUpdateCb ) } );
}
That will make the event handler look up the symbol named "updateDVR" at the time the event is triggered, & it will call your spy as your test expects.
Edit: Updated to retain this.onUpdateCb so we can unregister the listener on close.