Expectations

Assertions in Jasmine are named as an expectation. An expectation can either be true or false. Every expectation takes an actual value as only argument. An expectation is then chained with a matcher, which takes the expected value as an argument.

expect(true).toBe(true);

Here, expect is an expectation and toBe is a matcher. To evaluate negative assertions, expect() is chained with a not before calling a matcher. Matchers are used for Boolean comparison and validation of an expected value. You will learn more about matchers in the next subsection. See the following code:

expect(false).not.toBe(true);

Get Test-Driven JavaScript Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.