我正在对用咖啡脚本编写的主干视图进行规范测试。
我有这个观点
class Test.Views.MainView extends Backbone.View
el: $('ul')
initialize: ->
@collection.on 'add', @render
这是我的规格文件
beforeEach ->
@collection = new Test.Collections.Services([{name:'test'}, {name:'build'}])
@main_view = new Test.Views.MainView
collection: @collection
当我运行我的规范时,我收到了这个错误消息
TypeError: this.collection is undefined
为什么集合没有分配给规范中的视图?
编译的javascripts:
视图.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 }); });