Event listeners & js-test-driver?

杀马特。学长 韩版系。学妹 提交于 2019-12-25 08:29:03

问题


My JS gets loaded after the DOM is ready. Once the DOM is ready, the JS checks certain aspects of the environment (window dimensions etc.), binds event listeners to specific elements and then, finally, runs.

How do I set this up in js-test-driver? I can use /*:DOC += ... */ to mock my HTML, but I'm not sure how to do that first, then load my script, and have it bind event listeners to elements in it.

Honestly, what I'd rather have is jstestdriver load my html page along with all the listed scripts, and use that as the starting point. Maybe there's a better tool? A plugin I can use?


回答1:


You can use jQuery's load() function to load the HTML page you want to test. In your JSTestDriver test function:

$('html').load('pageToLoad.html', function() {
    // load was performed - run your asserts here now
});

However, since this uses a callback function, you might have to use an Async Test Case.



来源:https://stackoverflow.com/questions/14636735/event-listeners-js-test-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!