Parameterized tests with Jasmine
From the Jasmine docs: Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.
If you’ve found your way into this article, you’re probably a JavaScript developer fed up with writing tests. Unit testing is, after all, very time consuming, and so, so redundant. So, how can we make writing tests easier and less arduous?
Parameterized tests
What exactly are parameterized tests and why should we be using them? Well, basically they allow us to execute one test as many times as we want, each with a set of different input and output values (parameters), without having to rewrite our test a million times. Very, very useful, people.
The best part is that parameterized tests allow us to handle edge cases so easily. After first testing your code with a set of normal variables, you can then add all the edge cases, such as empty strings, negative values, uncommon unicode characters, nulls, 0’s etc.
So, now that we know what they are and why they are such an advantage to us when testing, let’s get coding.
Let the coding begin
For example, let us consider the following Jasmine test, where we want to test our function “isValidName” with three different input values: