Book Image

WEB APP TESTING USING KNOCKOUT.JS

By : Roberto Messora
Book Image

WEB APP TESTING USING KNOCKOUT.JS

By: Roberto Messora

Overview of this book

Table of Contents (11 chapters)

Expectations and matchers


The core of a specification is expectations; the part of the code that literally executes the tests, trying to verify if the assumptions are met.

Jasmine provides a global function called expect, and a series of functions called matchers to build and verify an expectation. In the first example of this chapter, we used the following expectation:

describe("Given MyClass implementation", function () {
    var myObj = new MyClass();
    it("when accessing message, then it should be equal to \"Hello Jasmine!\"", function () {
        expect(myObj.message).toEqual("Hello Jasmine!");
    });
});

The expect function takes the target variable as the argument. We can then chain a matcher function (in this case, toEqual) that takes the value we want to compare with the target variable as the argument. Every matcher function returns the Boolean value true if the comparison is met and false if the comparison is not met.

We can also negate a matcher by placing the not property just...