Template for Testing with Jasmine

Drop in your code, drop in your Jasmine specs, and away you go!

HTML

<script src="http://searls.github.com/jasmine-all/jasmine-all-min.js"></script>

JavaScript

//--- SPECS -------------------------
var Die = 
{   
    roll: function() {
        return Math.floor(Math.random() * 5 + 1);
    }
}
describe("Random is one", function() {
  it("has a value of 1 with call fake", function() {
      spyOn(Math, 'random').andCallFake(function() {
          return 1;
      });
    expect(Math.random()).toBe(1);
  });
  it("has a value of 1 with and return", function() {
    spyOn(Math, 'random').andReturn(1); 
    expect(Math.random()).toBe(1);
  });
  it("has a value of 1 with and return and the object", function() {
     var die = Object.create(Die);
     spyOn(Math, 'random').andReturn(1);
     expect(die.roll()).toEqual(6);
  });

});