Jasmine Framework Introduction

by techrevolt

HTML

<script src="http://searls.github.io/jasmine-all/jasmine-all-min.js"></script>
<h2>
Jasmine Framework Introduction
</h2>

JavaScript

function helloWorld() {
  return "Hello world!";
}

function heyWorld() {
  return "Hey world!";
}

function myFunction() {
  return 4;
}

describe("Hello world", function () {
  it("says hello", function () {
    expect(helloWorld()).toEqual("Hello world!");
  });
  it("says hey", function () {
    expect(heyWorld()).toEqual("Hello world!");
  });
});


describe('Hello world', function () {

  beforeEach(function () {
    this.addMatchers({
      toBeDivisibleByTwo: function () {
        return (this.actual % 2) === 0;
      }
    });
  });

  it('is divisible by 2', function () {
    expect(myFunction()).toBeDivisibleByTwo();
  });

});