简体   繁体   中英

Running jasmine tests against multiple versions of jQuery

What's the best way to set up unit tests (in particular using Jasmine) which test using multiple versions of jQuery. The obvious way would be to have the global test page simply set up a series of iframes, but I wonder if there's a way to achieve it in a single page. As a naive first stab I've tried the following, which fails to run any tests.

Does anyone have any ideas how this could be modified, or a better approach to take?

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 library might do the trick, I haven't tried it myself yet though:

"Elegant way to test a plugin in multiple versions of jQuery. Works perfectly with QUnit (and probably other testing frameworks)."

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM