簡體   English   中英

針對多個版本的jQuery運行jasmine測試

[英]Running jasmine tests against multiple versions of jQuery

設置單元測試(特別是使用Jasmine)的最佳方法是使用多個版本的jQuery進行測試。 顯而易見的方法是讓全局測試頁面只設置一系列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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM