我在单元测试中尝试调用document.ready(function(){})时遇到了困难.假设我的javascript文件中有多个,其中一个在命名函数内部调用,即
function myFunction() {
$(document).ready(function() {
//...
});
}
Run Code Online (Sandbox Code Playgroud)
我如何在单元测试中实际调用它们,以便我可以实际测试它们?我正在使用JsTestDriver对我的javascripts进行单元测试.
谢谢.
正如标题所示,我试图调用$(document).ready(function(){...}); 来自另一个文件.代码段如下:
源文件:
$(document).ready(function () {
alert('document.ready function called!');
// a lot of code
}
Run Code Online (Sandbox Code Playgroud)
并在测试文件中:
TestFile.prototype.testDocumentReadyContents = function () {
// test code here trying to call the document.ready function
}
Run Code Online (Sandbox Code Playgroud)
我还没有取得任何成功.我尝试过document.ready.apply(),trigger('ready'),覆盖document.ready函数......但是无法调用它.仅供参考我将其作为单元测试的一部分进行调用.
谢谢.