use test cases in qunit for testing jquery widget

52 views Asked by At

I have a jquery widget called tsColor with a colorSpecifiedColumns function. As described in my post title, I was wondering if there was a test cases function in qunit to avoir re writing the same test again and again with just a different value.

For example a thing like :

//case value =1
//case value =2
//case value =3
//...
test('color the first 3 columns', function () {

    // Arrange        

    // Act
    $("#container").tsColor("colorSpecifiedColumns", value);

    // Assert
    equal($(".colored").length, value, "number of colored columns equals to value");

});
1

There are 1 answers

0
Juho On

I didn't quite get what you're looking for, but it might be a pattern similar to this?

function testValue(givenValue) {
    return function () {
        $("#container").tsColor("colorSpecifiedColumns", givenValue);
        equal($(".colored").length, givenValue,
            "number of colored columns equals to value");
    }
}

test('color the first 3 columns', testValue(1));
test('color the first 3 columns', testValue(2));
test('color the first 3 columns', testValue(3));