gpt4 book ai didi

javascript - 针对多个版本的 jQuery 运行 Jasmine 测试

转载 作者:行者123 更新时间:2023-11-29 15:48:02 24 4
gpt4 key购买 nike

设置使用多个版本的 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();

最佳答案

$versions jQuery 库可能会成功,不过我自己还没有尝试过:

“在多个 jQuery 版本中测试插件的优雅方式。与 QUnit(可能还有其他测试框架)完美配合。”

https://github.com/protonet/jquery-versions

关于javascript - 针对多个版本的 jQuery 运行 Jasmine 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8782749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com