1
是否有任何方法在一次测试中有多个参数,而不是再次复制和粘贴该函数?在NUnit的JS单元测试使用不同参数运行多次
C的例子#:
[TestCase("0", 1)]
[TestCase("1", 1)]
[TestCase("2", 1)]
public void UnitTestName(string input, int expected)
{
//Arrange
//Act
//Assert
}
我想在JS:
describe("<Foo />",() => {
[TestCase("false")]
[TestCase("true")]
it("option: enableRemoveControls renders remove controls", (enableRemoveControls) => {
mockFoo.enableRemoveControls = enableRemoveControls;
//Assert that the option has rendered or not rendered the html
});
});
只是做一个新的功能,并称它,我猜。一般来说,因为你正在向'it'(和'describe'等)传递一个回调函数,所以你可以创建一个返回回调函数的函数makeTest(input,expected){return function(){assert(input == =“expected”)})''然后在测试中调用它it(“pass”,makeTest(1,1))'并改变它的参数it(“failed”,makeTest(“apple”,“orange”)) ' – vlaz