Jasmine is a testing framework for JavaScript. It’s framework agnostic and does not require a DOM. There are few matchers we built-in matchers helping us. Get a full control of them is essential to understand the basic functionality.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
describe('Testing all Jasmine built-in matchers', function() { it("equal to", function(){ expect(t).toEqual(t); }); it("toBe", function(){ expect(n).toBe(n); }); it("not.toBe", function(){ expect(t).not.toBe(Array); }); it("not.toContain", function(){ expect(a).not.toContain('Pepe'); }); it("not match to", function(){ expect(t).not.toMatch(f); }); it("is defined", function () { expect(n).toBeDefined(); }) it("is not defined", function () { var n; expect(n).toBeUndefined(); }); it("is null", function () { expect(nul).toBeNull(); }); it("is true", function () { expect(t).toBeTruthy(); }); it("is false", function () { expect(f).toBeFalsy(); }); it("contain an element", function () { expect(a).toContain('leo'); }); it("is lower than", function () { expect(f).toBeLessThan(t); }); it("is higher than", function () { expect(t).toBeGreaterThan(f); }); it("throws exception", function () { expect(function(){fn();}).toThrow(); }); }); |
jasmine unit-test:
http://jsfiddle.net/leolanese/HQsME/
jasmine complete list of matchers:
http://pivotal.github.com/jasmine/jsdoc/symbols/jasmine.Matchers.html
Working with jasmine: Testing Leo Fibonacci Numbers using Jasmine.
http://leolanese.com/blog/2012/08/21/fibonacci/