我正在对用coffeescript编写的骨干视图进行规范测试。
我有这个观点
class Test.Views.MainView extends Backbone.View
el: $('ul')
initialize: ->
@collection.on 'add', @render
这是我的spec文件
beforeEach ->
@collection = new Test.Collections.Services([{name:'test'}, {name:'build'}])
@main_view = new Test.Views.MainView
collection: @collection
当我运行我的规范时,我收到此错误消息
TypeError: this.collection is undefined
为什么集合没有从规范中分配给视图?
已编译的javascripts:
view.js
Test.Views.MainView = (function(_super) {
__extends(MainView, _super);
function MainView() {
this.render = __bind(this.render, this);
_ref = MainView.__super__.constructor.apply(this, arguments);
return _ref;
}
MainView.prototype.el = $('#main');
MainView.prototype.initialize = function() {
this.collection.on('change', this.render); //this line generates the error
};
规范
beforeEach(function() {
this.collection = new Test.Collections.Services([{name:'test'}, {name:'build'}]);
return this.main_view = new Test.Views.MainView({
collection: this.collection
});
});