JasmineJS Matchers - JasmineJS

What are Jasmine JS Matchers?

Jasmine Js is a testing framework, hence it aims to compare the output of the JavaScript file or function with the expected result. Matcher works similarly in Jasmine framework.

Matchers in Jasmine are the JavaScript function which does a Boolean comparisons between two operators, I.e an actual output and an expected output.

There are two types of matchers in Jasmine.js, Inbuilt matcher and Custom matchers.

Inbuilt Matcher

Inbuilt Matcher are the matchers which are inbuilt in the Jasmine framework. The user can easily use it.

The below example displays on how Inbuilt Matcher works with Jasmine framework.

We had already used some matchers in the earlier chapters.

In the above example, toEqual() is the inbuilt matcher which will compare the result of the add() and addAny() methods with the arguments passed to toEqual() matchers.

Custom Matchers

Custom matcher are the matchers which are not present in the inbuilt system library of Jasmine. These matcher are needed to be defined explicitly(). In the below example, we will see how the custom matcher works.

In the example stated above, validateAge() works as a matcher which is actually validating our age with some range. In this example, validateAge() works as a custom matcher. Add this JS file into SpecRunner.html and run the same. It will produce the below result.

Custom Matchers

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JasmineJS Topics