admin管理员组文章数量:1415137
I would like to know how can I check if an element on the UI exists by id or class. I'm using teaspoon-mocha, Sinon, and chai.
I tried next but it doesn't work:
expect($('my-id')).to.be.true;
I would like to know how can I check if an element on the UI exists by id or class. I'm using teaspoon-mocha, Sinon, and chai.
I tried next but it doesn't work:
expect($('my-id')).to.be.true;
Share
Improve this question
edited Jun 18, 2018 at 11:47
Ahmed Ashour
5,61110 gold badges39 silver badges62 bronze badges
asked Jun 18, 2018 at 11:45
JakubJakub
2,7398 gold badges45 silver badges104 bronze badges
1 Answer
Reset to default 5It would be nice to have slightly more context, but generally speaking with jQuery you should check the length of array returned. And if you use an id the '#'
sign must be there. Another thing is that the .true
assertion in chai uses a strict ===
parison (http://www.chaijs./api/bdd/#method_true). So, either
expect($('#my-id').length === 1).to.be.true;
or
expect($('#my-id').length).to.be.ok;
本文标签: javascriptHow do I check if element exists with Mocha Chai SinonStack Overflow
版权声明:本文标题:javascript - How do I check if element exists with Mocha Chai Sinon? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745212180a2647954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论