为什么集合未分配给此代码中的主干视图

时间:2013-08-14 06:43:13

标签: backbone.js coffeescript jasmine

我正在对用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:

  1. 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     
        };
    
  2. 规范

    beforeEach(function() {
      this.collection = new Test.Collections.Services([{name:'test'}, {name:'build'}]);
      return this.main_view = new Test.Views.MainView({
        collection: this.collection
      });
    });
    

0 个答案:

没有答案