Introduction to Jasmine framework
Jasmine is a behavior-driven development framework for testing JavaScript code. This is how the official site explains Jasmine:
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.
The general syntax of a Jasmine test suite is given as follows:
describe("Sample Test Suite", function() { it("This is a spec that defines test", function() { expect statement // asserts the logic etc }); });
Let's analyze the preceding code snippet to understand the test suite syntax. The following steps have been followed:
- Every Jasmine test suite will have a
describe
statement, where we can give a name. - Inside the test suite, we create smaller tests cases using the
it
statement; each test case will have two parameters, a name and a function, which will have our application logic that needs be tested...