André Faria Gomes @andrefaria
Jasmine is a behavior-driven development framework for testing your JavaScript code.
It does not depend on any other JavaScript frameworks
It does not require a DOM
It has a clean, obvious syntax so that you can easily write tests.
Specs
Expectations
Suites
Nested
Disabling describe => xdescribe it => xit
Matchers expect(x).toEqual(y); expect(x).toBe(y); //same expect(x).toMatch(pattern); //regex expect(x).toBeDefined(); //not undefined expect(x).toBeNull(); expect(x).toBeTruthy(); expect(x).toBeFalsy(); expect(x).toContain(y); //for arrays or strings expect(x).toBeLessThan(y); expect(x).toBeGreaterThan(y); expect(fn).toThrow(e); expect(x).not.toEqual(y);
Your Matchers
Before & After
Spies Spies are automatically removed after each spec. They may be set in the beforeEach function
Spying Static Methods
Spying Instance Methods
Spying CallBacks
Spying AJAX
Spying Matchers expect(x).toHaveBeenCalled() expect(x).toHaveBeenCalledWith(arguments) expect(x).not.toHaveBeenCalled() expect(x).not.toHaveBeenCalledWith(arguments) spyOn(x, 'method').andCallThrough(): spies on AND calls the original function spied on spyOn(x, 'method').andReturn(arguments): returns passed arguments when spy is called spyOn(x, 'method').andThrow(exception): throws passed exception when spy is called spyOn(x, 'method').andCallFake(function): calls passed function when spy is called Spy Properties callCount: returns number of times spy was called mostRecentCall.args: returns argument array from last call to spy. argsForCall[i] returns arguments array for call i to spy.
Asynchronous Specs runs
Asynchronous Specs waiting
Asynchronous Specs waiting condiction
HTML /src SpecRunner.html /spec
Ruby Gem
NodeJS package npm install jasmine-node --global jasmine-node scripts
Java maven
References https://github.com/pivotal/jasmine

Testing Javascript with Jasmine