javascript - Is there any QUnit assertion/function who test whether element in array or not -
i have array of expected output in qunit function.now want test result of function in array or not.
var =new array('abc','cde','efg','mgh');
now question is there qunit assertion/function can me ??
i know js coding create method check wanna spefic ounit !!!!
if have javascript 1.6 can utilize array.indexof
test("myfunction expected value", function() { var expectedvalues = ['abc','cde','efg','mgh']; ok(expectedvalues.indexof(myfunction()) !== -1, 'myfunction() should homecoming expected value'); });
if want can extend qunit back upwards these kind of assertions:
qunit.extend(qunit, { inarray: function (actual, expectedvalues, message) { ok(expectedvalues.indexof(actual) !== -1, message); } });
then can utilize custom inarray()
method in tests:
test("myfunction expected value", function() { var expectedvalues = ['abc','cde','efg','mgh']; qunit.inarray(myfunction(), expectedvalues, 'myfunction() should homecoming expected value'); });
i created a jsfiddle show both options.
javascript unit-testing qunit
No comments:
Post a Comment