Event listeners & js-test-driver?

2019-09-06 11:21发布

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条回答
戒情不戒烟
2楼-- · 2019-09-06 11:31

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.

查看更多
登录 后发表回答