他们是否有办法在一个测试中具有多个参数,而不是再次复制和粘贴函数?

NUnit中的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 -call放在函数中,并使用不同的参数进行调用:

describe("<Foo />", () => {

    function run(enableRemoveControls){
        it("option: enableRemoveControls renders remove controls", () =>  {
            mockFoo.enableRemoveControls = enableRemoveControls;

            //Assert that the option has rendered or not rendered the html
        });
    }

    run(false);
    run(true);
});

07-25 23:06