About the Jasmine framework

Jasmine is a leading open source testing framework for writing and testing automated test scripts for modern web frameworks. 

Certainly, for Angular, Jasmine has become the de facto, go-to framework. The following is taken from the official website:

"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 idea behind writing Jasmine test scripts are behaviorally and functionally driven. Test scripts have two important elements—describe and the specs (it):

  • The describe function is for grouping related specs together.
  • The specs are defined by calling the it function.

Here's a sample test script, which is written in Jasmine:

describe("Test suite", function() {
  it("contains spec with an expectation", function() {
    expect(true).toBe(true);
  });
});

In the process of writing test specs, we have to use a lot of conditional checks to match data, elements, results, asserting conditions, and much more. The Jasmine framework provides a lot of matchers, which we can readily use while writing our test specs. In the preceding sample code, toBe is one such example of a matcher.

Here's a list of the most commonly and frequently used matchers in Jasmine:

  • toBe
  • toBeTruthy
  • toBeFalsy
  • toBeGreaterThanOrEqual
  • toBeLessThanOrEqual
  • toHaveBeenCalled
  • toHaveClass
  • toMatch

We will learn how to use these matchers in the next few sections. OK, we have written our test specs, so now what? How do we run them? What will run them for us? The answers can be found in the next section. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.61.142