Is their any way to have multiple parameters in one test instead of copying and pasting the function again?
Example in NUnit for C#:
[TestCase("0", 1)] [TestCase("1", 1)] [TestCase("2", 1)] public void UnitTestName(string input, int expected) { //Arrange //Act //Assert }
What I want in 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 }); });
You need to add the annotation @RunWith(Parameterized.
Tests should never depend on each other. If your tests have to be run in a specific order, then you need to change your tests. Instead, you should make proper use of the Setup and TearDown features of your unit-testing framework to ensure each test is ready to run individually.
JavaScript Unit Testing is a method where JavaScript test code is written for a web page or web application module. It is then combined with HTML as an inline event handler and executed in the browser to test if all functionalities are working as desired. These unit tests are then organized in the test suite.
An alternative is to use Jest. It has this functionality built-in:
test.each` a | b | expected ${1} | ${1} | ${2} ${1} | ${2} | ${3} ${2} | ${1} | ${3} `('returns $expected when $a is added $b', ({a, b, expected}) => { expect(a + b).toBe(expected); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With