Getting started with jasmine

Installation or Setup

Installing Jasmine standalone

Download the latest Jasmine release from the Jasmine release page:

Running Jasmine locally

  1. Run Jasmine in the browser by downloading the zip file, extracting it, the referencing the files as follows:

Installing Jasmine using npm (Node Package Manager)

  1. Set up project directory for Jasmine

    Create a folder and run npm init this will create an empty package.json file and will ask some questions about your project to fill project json file.

    Add 2 directories app - for the Server and spec - for tests

  2. Get Jasmine

    From root project directory run

    npm install jasmine-node --save

    npm install request --save

    npm install express --save

    this will get you the packages

    ./node_packages/.bin/jasmine-node spec will run jasmine binary

    After this your package.json should look similar to this

    package.json file, after which that file should look like this:

    { “name”: “Jasmine”, “version”: “0.0.1”, “description”: “Jasmine”, “main”: “index.js”, “scripts”: { “test”: “./node_modules/.bin/jasmine-node spec” }, “author”: “Me”, “license”: “ISC” }

Install with npm

npm install -g jasmine

If being used with karma, install karma-jasmine

npm install --save-dev karma-jasmine

Hello World

To create a most basic test with Jasmine go to your spec (tests) folder and add file named testSpec.js.

In that file add following:

var request = require("request");

describe("Hello World Test", function() {
  // This is your test bundle

  describe("GET SO", function() {
    //This is testing that http GET works

    it("Checks if SO is online", function() {
      // This is description of your test - this is what you get when it fails
      request.get("", function(error, response, body) {
        // this is your test body

        // this is your test assertion - it expects status code to be '200'