【发布时间】:2011-10-20 09:43:48
【问题描述】:
在我的应用程序中,我有一个视图绑定到 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 == ''
我错了还是这不应该是正确的行为?
【问题讨论】:
-
问题似乎是主干视图找不到由 jasmine-jquery.js 创建的夹具:如果我将元素传递给集合的构造函数(即:el: $(' #myElement')) evrithing 工作正常
标签: javascript backbone.js jasmine jasmine-jquery