事件监听器js-test-driver? [英] Event listeners & js-test-driver?

查看:122
本文介绍了事件监听器js-test-driver?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在DOM准备好后,我的JS被加载了. DOM准备就绪后,JS将检查环境的某些方面(窗口尺寸等),将事件侦听器绑定到特定元素,然后最终运行.

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.

如何在js-test-driver中进行设置?我可以使用/*:DOC + = ... */来模拟我的HTML,但是我不确定如何首先执行该操作,然后加载我的脚本并将其绑定到事件侦听器.其中的元素.

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.

老实说,我更希望jstestdriver加载html页面以及所有列出的脚本,并将其作为起点.也许有更好的工具?我可以使用一个插件吗?

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?

推荐答案

您可以使用jQuery的 load()函数,以加载要测试的HTML页面.在您的JSTestDriver测试功能中:

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.

这篇关于事件监听器js-test-driver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆