diff --git a/_faq/testing/parameterized.md b/_faq/testing/parameterized.md new file mode 100644 index 0000000..7a6bd98 --- /dev/null +++ b/_faq/testing/parameterized.md @@ -0,0 +1,25 @@ +--- +question: Does Jasmine support parameterized testing? +--- + +Not directly. But test suites are just JavaScript, so you can do it anyway. + +```javascript +function add(a, b) { + return a + b; +} + +describe('add', function() { + const cases = [ + {first: 3, second: 3, sum: 6}, + {first: 10, second: 4, sum: 14}, + {first: 7, second: 1, sum: 8} + ]; + + for (const {first, second, sum} of cases) { + it(`returns ${sum} for ${first} and ${second}`, function () { + expect(add(first, second)).toEqual(sum); + }); + } +}); +``` \ No newline at end of file