If you have JavaScript 1.6, you can use Array.indexOf
test("myFunction with expected value", function() { var expectedValues = ['abc','cde','efg','mgh']; ok(expectedValues.indexOf(myFunction()) !== -1, 'myFunction() should return an expected value'); });
If you want, you can extend QUnit to support such statements:
QUnit.extend(QUnit, { inArray: function (actual, expectedValues, message) { ok(expectedValues.indexOf(actual) !== -1, message); } });
Then you can use this custom inArray() method in your tests:
test("myFunction with expected value", function() { var expectedValues = ['abc','cde','efg','mgh']; QUnit.inArray(myFunction(), expectedValues, 'myFunction() should return an expected value'); });
I created jsFiddle to show both options .
source share