Testing backbone.js application with jasmine - how to test model bindings on a view?

前端 未结 6 1602
-上瘾入骨i
-上瘾入骨i 2020-12-24 02:48

I had some interesting tribulations in trying to test whether views were correctly bound to events.  In backbone, we typically bind to events in the initialize method, using

6条回答
  •  情深已故
    2020-12-24 03:43

    I have managed to achieve this using prototype patching. Before you create the instance of the view, spyOn the constructor's prototype.

    spyOn(MyView.prototype, 'changeSelected');
    var view = new MyView();
    view.selectSomething();
    expect(view.changeSelected).toHaveBeenCalled();
    

提交回复
热议问题