Book Image

Learning Single-page Web Application Development

Book Image

Learning Single-page Web Application Development

Overview of this book

Table of Contents (15 chapters)
Learning Single-page Web Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing Jasmine


Karma is one of the most commonly used tools for test execution; it is compatible with many testing frameworks (such as Mocha, QUnit, and Jasmine). You can use it to test any JavaScript code, and it is highly recommended that you use some tool to test and perform automated testing on SPA.

In the following examples, we will be using Jasmine to write the tests and Karma to run the test. Jasmine has a very simple and easy writing syntax. Also, it is not dependent on any other framework. A basic example of writing tests looks like the following code:

describe("The test name", function() {
  it("contains spec with an expectation", function() {
    expect(true).toBe(true);
  });
});

describe() and it() are two functions. The describe() function has two parameters: a string parameter that receives the name of the test, and a function parameter that implements the spec using the it() function. The expect() function is a matcher function to get a result. The matcher function receives...