admin管理员组文章数量:1332389
I'm working on a Backbone.js application and while adding tests with Jasmine & Sinon I had problems to determine the visibility of some DOM elements: some of them where detected as not visible in the tests while I could see them correctly in my application.
I created a small example that replicates the problem, the same test is run twice on two sets of elements:
- the first set is present directly in SpecRunner.html
- the second one has been rendered as a Backbone view
The test itself is using jQuery.is(':visible')
(via jasmine-jquery's .toBeVisible()
) to know if elements are visible or not. It passes for the first set, not for the second one.
I shared the code here as a github project :
I guess I forgot something, or maybe misused a library, but I can't put my finger on it so if you have any clue... :)
Thanks! Maxime
I'm working on a Backbone.js application and while adding tests with Jasmine & Sinon I had problems to determine the visibility of some DOM elements: some of them where detected as not visible in the tests while I could see them correctly in my application.
I created a small example that replicates the problem, the same test is run twice on two sets of elements:
- the first set is present directly in SpecRunner.html
- the second one has been rendered as a Backbone view
The test itself is using jQuery.is(':visible')
(via jasmine-jquery's .toBeVisible()
) to know if elements are visible or not. It passes for the first set, not for the second one.
I shared the code here as a github project : https://github./maximevaly/3789_js
I guess I forgot something, or maybe misused a library, but I can't put my finger on it so if you have any clue... :)
Thanks! Maxime
Share asked Jun 7, 2012 at 12:00 Maxime ValyMaxime Valy 1131 silver badge5 bronze badges1 Answer
Reset to default 9The issue is that your StuffView.el
is not attached to DOM, hence is always not visible. You probably misunderstand className
and tagName
parameters: they aren't used as selectors, but to construct a brand new element.
This fixes the second test.
el : "div.container",
//tagName : 'div',
//className : 'container',
Alternatively you can attach the view to DOM manually in the test
$("body").append(this.view.el);
本文标签: javascriptI can39t test the visibility of elements rendered in my backbone viewStack Overflow
版权声明:本文标题:javascript - I can't test the visibility of elements rendered in my backbone view - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742291186a2447827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论