如何在单元测试中调用$(document).ready(function(){}) [英] How to invoke $(document).ready(function() {}) in unit testing
问题描述
我在单元测试中尝试调用document.ready(function(){})时遇到了困难。假设我的javascript文件中有多个,其中一个在命名函数内部调用,即
I'm experiencing difficulties trying to invoke document.ready( function() {}) in my unit tests. Suppose I have multiple of them in my javascript file, and one of them called inside a named function i.e.
function myFunction() {
$(document).ready(function() {
//...
});
}
我如何在单元测试中实际调用它们以便我可以实际测试它们?我正在使用JsTestDriver对我的javascripts进行单元测试。
How do I actually invoke them in my unit tests so I can actually test them? I'm using JsTestDriver to unit test my javascripts.
谢谢。
推荐答案
可以在此处找到此问题的部分答案。
Part of the answer to this question can be found here.
以下是基于以上答案回答此问题的示例代码:
Below is the sample code to answer this question based on the above answer:
myFunction();
$.readyList[1]();
索引假定源文件中只有1个document.ready函数。索引0指的是我认为是浏览器信息的其他内容。
The index assumes that there is only 1 document.ready function in the source file. Index 0 refers to something else which I believe is info on the browser.
这篇关于如何在单元测试中调用$(document).ready(function(){})的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!