Chapter 2. Jasmine
What Is Jasmine?
Jasmine is a behavior-driven testing framework for JavaScript programming language. Itâs a bunch of tools that you can use to test JavaScript code.
As you learned in the previous chapter, you can test your code against specifications that you write. If your code should work in a certain way, Jasmine helps you express that intention in code.
(By the way: if youâve played around with RSpec for testing Ruby, Jasmine will look suspiciously familiar.)
Getting Set Up with Jasmine
Start by downloading the latest standalone release of Jasmine. Unzip it.
Note
Throughout this book, weâll mostly be using browser-based Jasmine for various reasons. If youâd prefer a different environment (Node.js, Ruby/Rails, or other environments), take a look at Chapter 7, or the Jasmine wiki. These instructions are for a browser-based environment.
When you open SpecRunner.html in a web browser, youâll see something like Figure 2-1.
This file has run some example tests on some example code. Itâs testing a Player
and a Song
. Whenever you want to run the tests, you simply need to load/reload this page.
In the src directory, youâll see two things to be tested: a Player
and a Song
. The spec directory has tests for the Player
. Taking a look inside the spec directory might help you understand Jasmineâs syntax (though thereâs also ...
Get JavaScript Testing with Jasmine 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.