0

私のアプリケーションでは、すでにDOMにあるhtml要素にバインドされたビューがあります

var myView = Backbone.View.extend({
  ...
  el: '#myElement',
  ...
});

次のジャスミン テストに問題があります。

beforeEach(function(){
            //fixiture created with jasmin-jquery.js plugin
        setFixtures('<div id="myElement"></div>');

        this.myView = new MyView({model: new Model()); 
    });
describe('when instantiated', function(){
it('should be associated to #myElement', function(){
            expect(this.app.el).toBeDefined();
            expect(this.app.el).toBe($('#myElement'));
        });
});

テストは失敗し、 this.app.el == '' であることが判明しました

私は間違っていますか、これは正しい動作ではありませんか?

4

1 に答える 1

1

ビューがそれを接続できるように、フィクスチャに「myElement」IDを含めるべきではありませんか?

setFixtures('<div id="myElement"></div>');
于 2011-10-20T10:00:08.760 に答える