设置单元测试(特别是使用Jasmine)的最佳方式是使用多个版本的jQuery进行测试。显而易见的方法是让全局测试页面设置一系列iframe,但我想知道是否有方法在单个页面中实现它。作为一个天真的第一刺,我已经尝试了以下,未能运行任何测试。针对jQuery的多个版本运行jasmine测试
有没有人有任何想法如何修改,或更好的方法?
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();
审议这个多了,我想我们需要的是异步运行茉莉测试套件的一些方法,所以我打算用waitsFor()方法 – wheresrhys 2012-01-09 10:54:37
关于进一步反射实验,我想的iframe解决方案是最好的,因为它也允许对各种文档类型进行测试,但是如果任何人仍然觉得像上面提到的那样找到探针的解决方案,我仍然很想知道如果可能的话。 – wheresrhys 2012-01-09 11:35:16