【发布时间】:2012-02-05 15:40:28
【问题描述】:
设置使用多个版本的 jQuery 进行测试的单元测试(尤其是使用 Jasmine)的最佳方法是什么。显而易见的方法是让全局测试页面简单地设置一系列 iframe,但我想知道是否有办法在单个页面中实现它。作为一个天真的第一次尝试,我尝试了以下方法,但无法运行任何测试。
有没有人知道如何修改它或采取更好的方法?
function testSuite() {
describe("jquery.flickbook", function() {
it("makes testing JavaScript awesome!", function() {
expect(true).toBeTrue();
});
});
}
function testAllJquerys() {
var jqueryInclude = document.getElementById("jquery"),
head = document.getElementsByTagName("head")[0],
versions = "1.6,1.7.1,1.5.1".split(",");
function runSuite() {
describe("jquery-" + version, testSuite);
switchjQuery();
}
function switchjQuery() {
version = versions.shift();
// jQuery = $ = null;
jqueryInclude = document.createElement("script");
jqueryInclude.type = "text/javascript";
if (jqueryInclude.addEventListener){
jqueryInclude.addEventListener('load', runSuite, false);
} else if (jqueryInclude.attachEvent){
jqueryInclude.attachEvent('onload', runSuite);
}
head.appendChild(jqueryInclude);
jqueryInclude.src = "../../jquery/jquery-" + version + ".js";
}
switchjQuery()
}
testAllJquerys();
【问题讨论】:
-
考虑到这一点,我认为需要一些异步运行 jasmine 测试套件的方法,所以我将尝试使用 waitsFor() 方法
-
经过进一步思考,我认为 iframe 解决方案是最好的,因为它还允许针对各种 doctype 进行测试,但如果有人仍然想找到上述问题的解决方案,我仍然很好奇知道是否可能
标签: javascript jquery unit-testing jasmine