jasmine JS testing Cheat Sheet

A Programming › JavaScript cheat sheet in English by CITguy

DOM-less simple JavaScript testing framework

89,136 views 15,406 downloads 14 May 2013 History
4.7 avg · 10 ratings

jasmine statements

describe( label, functi­on(){ ... })
group tests together
it( label, functi­on(){ ... })
label individual test
expect( actual )
used to compare against expected values
beforeEach(funct­ion(){ ... })
run prior to each it in the describe
afterEach(funct­ion() { ... })
run after each it in the describe
xdescribe( label, functi­on(){ ... })
skip section ( note the x )
xit( label, functi­on(){ ... })
skip test ( note the x )

jasmine matchers

to(Not)Be( null | true | false )
to(Not­)Equal( value )
to(Not­)Match( regex | string )
toBeDe­fined()
toBeUn­defined()
toBeNull()
toBeTruthy()
toBeFalsy()
to(Not­)Co­ntain( string )
toBeLe­ssThan( number )
toBeGr­eat­erThan( number )
toBeNaN()
toBeCl­oseTo( number, precision )
toThrow()
Matchers can be chained with a not between the actual and assertion.

jasmine double­s/spies

spyOn( obj, method­_string )
obj.st­ubbed.calls
array
obj.st­ubbed.mostRe­cen­tCall
call object
obj.st­ubb­ed.c­al­ls[0].args
array
toHave­Bee­nCalled()
toHave­Bee­nCa­lle­dWith( array )
andCal­lTh­rough()
spy and delegate to real object
andReturn( value )
andCal­lFake(funct­ion() { ... })
jasmine.createSpy( id )
jasmine.create­SpyObj( baseName, methods[] )
jasmine.any( constr­uctor )

Badges

Useful Cheat Sheet Great Cheat Sheet Nice Cheat Sheet Good Cheat Sheet Appreciated Cheat Sheet Downloaded from Unusual Locations × 2 🇰🇷 Big in Korea (South) 🇭🇰 Big in Hong Kong

Comments (8)

Doug 10:02 22 Oct 2015

Thanks! great list, the syntax is outdated. spyOn now uses dot for callThrough and returnValue such that .andCallThrough became .and.callThrough

Reply
Karan 10:52 16 Oct 2015

Beware, this cheat sheet contain hidden characters, so direct copy paste to Visual Studio will result in "Uncaught SyntaxError: Unexpected token ILLEGAL" exception when running JavaScript in the Browser.

Reply
Sofyan 09:57 4 Aug 2015

Helpfull cheat sheet, Thank you.

Reply
Troy 12:17 8 Jun 2015

"ddescribe" and "iit" were renamed to "fdescribe" and "fit". (The f standing for focus)

Reply
Monisgnor 09:10 20 Nov 2014

The list is not complete. There are no "ddescribe", "iit" and perhaps other methods.

Reply
Vinny 12:05 11 Nov 2014

Can you create a cheat sheet for Jasmine 2.x?

Reply
Elder 09:34 31 Oct 2014

Thank you! :)

Reply
Brian Ledsworth 13:37 19 Apr 2014

Thanks.

Reply

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.