在测试中,如果用到了大量相同的方法返回判断结果,可以将他们简化;
使用push():
push( result/*boolean,result of assert*/, actual, /*object,expression being test*/ expected, /*comparison value*/ message /*description of pass*/ )
例子:
QUnit.assert.mod2 = function(vlaue,expected,message) { //方法名自定义; var actual = vlaue % 2; this.push(actual === expected, actual ,expected, message); //push替代ok,equal等判断; } QUnit.test("mod2",function(assert) { assert.expect(2); assert.mod2(2,0,"2 % 2 === 0"); assert.mod2(3,1,"3 % 2 === 1"); });
通过rul筛选:在URL上添加?filter=name-of-test