Something about ‘JASMINE’

Nishant Sharma
TestVagrant
2 min readMay 31, 2019

--

As you must have noticed in the previous post, we looked into a simple example of jasmine code, which navigates to a to-do list in AngularJS page.

So here, we’ll be talking more about jasmine, mainly about jasmine syntax

The Structure

Jasmine is an open-source testing framework for JavaScript

describe()

Everything in a jasmine file starts in a describe block. Consider this as the main section. Describe block can have multipledescribe blocks within itself, which are considered as subsections (nested blocks)

It

A describe block consists of one or more it blocks which act a separate test case. The definition of an it block is same as a describe block.

Now let’s see some functions that are used in jasmine:

BeforeEach and AfterEach

There will always be something which you wanna perform every time before and after each it() block. One way to achieve this is to call that particular code every time in your it() block, but then isn’t this redundant? The easiest way of implementing this function is by using the same code inside beforeEach() and afterEach() function once, an example would be something like this:

Some matchers in jasmine….

Once you have created your test cases, you wanna do some validations, which can be done by using expect()statements that are available inside the jasmine framework.

toBe()

The defination of toBe() is if both the values inside expect() and toBe() match with each other, then your test is passed, else failed.

not.toBe()

not.toBe() is just the opposite of toBe() .i.e if both the values inside expect() and toBe() don’t match with each other, then your test is passed, else failed.

toEqual()

It checks whether the actual text is equal to the expected text.

toMatch()

This will match the complete or partial text to be same as expected text.

--

--

Nishant Sharma
TestVagrant

Currently learning everything, plays video games too.