Question

I'm getting the hang with Jasmine and JSTestDriver on PhpStorm, and I'm trying to have ONE js test file to unit test against multiple versions of jquery (namely 1.7.x, 1.8.x, 1.9.0 and 2.0b). What is the best way to do this? I've read a few questions here in SO with no actual answers.

  • Put the describe inside a loop and load/remove each jQuery manually?
  • I'm using jasmine-jquery, so I can load fixtures, but I don't know how to load js files with it, since it seems to be HTML only (and json / css)
  • Loading each script progressively, calling jQuery.noConflict can make it work?
  • Would I have to reload my jQuery plugin each time the jQuery version changes?
Was it helpful?

Solution

After hours of trying, I've managed to do this. It's pretty simple actually, I was just trying to reinvent the wheel, using LAB.js I was able to do it quite easily, this is inside your test.js (and the result log is pretty nice too):

function run() {
  describe("My code on jQuery " + ($().jquery), function () {
    // do your thing
  });
}

var
  $versions = ['1.7.1','1.7.2','1.8.0','1.8.1','1.8.2','1.8.3','1.9.0','2.0.0b1'];

for (var i = 0; i < $versions.length; i++) {
  $LAB
    .setOptions({AlwaysPreserveOrder:true, AllowDuplicates:true, CacheBust:true, BasePath:'/test/'})
    .script('tests/lib/jquery-' + ($versions[i]) + '.js')
    .script('tests/lib/jasmine-jquery.js')
    /* .script('any-other-lib.js') */
    .wait(run);
}

Everything loaded in $LAB loads synchronously and in order, so you can always ensure the load order of the scripts. Pretty simple and with continuous integration, it can run in the background of the IDE without any hassle (unless sometimes the runner won't cleanup and will throw an exception saying $ is undefined)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top