Krishnan
Krishnan

Reputation: 1008

Unit testing in angular with various test data

If I need to do unit testing for any c# method with various sets of data, then I can use the Theory and InlineData to pass varios inputs for testing a method.

[Theory]
[InlineData("88X", "1234", "1234", "1234")]
[InlineData("888", "123X", "1234", "1234")]
public void ShouldReturnInValidIfCustomerInformationDoestMatch(
    string locationId,
    string quoteBillTo,
    string quoteSoldTo,
    string quoteShipTo)
{
    ....
}

Similarly is there any way to unit test in Angular/Jasmine/Karma to validate the same functionality/method with various set of input data?

Upvotes: 0

Views: 1275

Answers (1)

Andoni
Andoni

Reputation: 171

It is not related to Angular but with your test runner but you can try something like:

[
  { parameter: 1, result: 2 },
  { parameter: 3, result: 4 },
].forEach((dataSet) => {
  it('should be ' + dataSet.result + ' when parameter is ' + dataSet.parameter, () => {
    const result = library.calculate(dataSet.parameter);
    expect(result).toBe(dataSet.result);
  });
});

Upvotes: 1

Related Questions