[英]Testing backbone.js application with jasmine - view with bound element
In my application I have a view which comes bound to an html element already in the DOM在我的应用程序中,我有一个视图绑定到 DOM 中已有的 html 元素
var myView = Backbone.View.extend({
...
el: '#myElement',
...
});
I've a problem with the following jasmine test:我对以下茉莉花测试有问题:
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'));
});
});
the test fails and it turns out that this.app.el == ''测试失败,结果是 this.app.el == ''
Am I wrong or this shouldn't be the correct behavior?我错了还是这不应该是正确的行为?
您的装置不应该包含“myElement”ID 以便您的视图可以连接它吗?
setFixtures('<div id="myElement"></div>');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.