Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WEB APP TESTING USING KNOCKOUT.JS

You're reading from   WEB APP TESTING USING KNOCKOUT.JS Design, implement, and maintain a fully tested JavaScript web application using Knockout.JS

Arrow left icon
Product type Book
Published in Nov 2014
Publisher
ISBN-13 9781783982844
Pages 154 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
ROBERTO MESSORA ROBERTO MESSORA
Author Profile Icon ROBERTO MESSORA
ROBERTO MESSORA
Arrow right icon
View More author details
Toc

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime