Search code examples
resharperqunit

Inconsistency in Resharper's qunit test runner


I would like to use Resharper's (8.0.2) integrated qunit test runner, but there are some differences when running a test directly in a browser vs running it in a browser using the R# runner:

  1. As pointed out here, a fixture element is not added, which is needed for UI related tests. As described in the answer, it can be solved by manually adding the element in a module setup + teardown methods.

    Which brings me to the next issue:

  2. Resharper only regognizes the deperecated setup and teardown, and not their replacements (beforeEach and afterEach):

DEPRECATION Note: beforeEach and afterEach were previously named setup and teardown, which still exist and will be removed in QUnit 2.0.0.

module("Tests for DOM manipulation", {
    beforeEach: function () { // never called in the R# runner
        $("body").append('<div id="qunit-fixture" />');
    }
});

test('finding qunit-fixture element', function(){
    var elementCount = $('#qunit-fixture').length;
    ok(elementCount, 1);
});

Finally, the test() callback function doesn't return an assert object, i.e:

test('foo', function(assert){
    var done = asssert.async(); // assert is undefined in R# qunit runner
    setTimeout(function (){
        ok(1 === 1);
        done();
    }, 500);
});

Is there any way to make R# behave more like a "native qunit" test implementation?


Solution

  • I'm not sure if this is exactly how you want this to work, but I wanted to run a newer version of QUnit than the one that comes bundled with R#.

    The simplest solution I had was to include QUnit-1.17.1 into my project, and in the top of my JavaScript test file, include:

    /// <reference path="../lib/qunit-1.17.1.js" />
    

    This will include that file before the rest of the script, so it will essentially overwrite the existing QUnit definition provided by R#.

    There might be problems with collisions, but I was able to get this to work:

    /// <reference path="../lib/qunit-1.17.1.js" />
    
    QUnit.test('this is my test', function(assert) {
        assert.equal(1, 1);
    });
    

    The test succeeds with the regular R# test runner.

    To clarify, the path ../lib/qunit-1.17.1.js is the file location relative to the test.js file.