0
我有與Math.floor((Math.random() * 9) + 1);
工作的一些功能,然後我用一個for
像其它邏輯中對它們進行測試:在jQuery QUnit中如何從「equal()」聲明中獲取斷言結果?
test("getRandomNumber(anyNumber) should return a number between 1..anyNumber", function() {
var anyNumber, result;
for (var i = 0; i <= 100; i++) {
anyNumber = Math.floor((Math.random() * 9) + 1);
result = getRandomNumber(anyNumber);
equal((0 < result && result < (anyNumber + 1)), true);
}
});
我想從equal
斷言得到的結果,如果一個斷言失敗,沒有按「T需要留在循環,如:
test("getRandomNumber(anyNumber) should return a number between 1..anyNumber", function() {
var anyNumber, result;
for (var i = 0; i <= 100; i++) {
anyNumber = Math.floor((Math.random() * 9) + 1);
result = getRandomNumber(anyNumber);
if (!equal((0 < result && result < (anyNumber + 1)), true));
break;
}
});