Show Menu
Cheatography

jasmine JS testing Cheat Sheet by

DOM-less simple JavaScript testing framework

jasmine statements

desc­ribe( label, functi­on(){ ... })
group tests together
it( label, functi­on(){ ... })
label individual test
expe­ct( actual )
used to compare against expected values
befo­reE­ach­(­fun­cti­on(){ ... })
run prior to each it in the describe
afte­rEa­ch­(f­unc­tion() { ... })
run after each it in the describe
xdes­cri­be( label, functi­on(){ ... })
skip section ( note the x )
xit( label, functi­on(){ ... })
skip test ( note the x )
 

jasmine matchers

to(N­ot)­Be( null | true | false )
to(N­ot)­Equ­al( value )
to(N­ot)­Mat­ch( regex | string )
toBe­Def­ine­d()
toBe­Und­efi­ned()
toBe­Nul­l()
toBe­Tru­thy()
toBe­Fal­sy()
to(N­ot)­Con­tain( string )
toBe­Les­sTh­an( number )
toBe­Gre­ate­rTh­an( number )
toBe­NaN()
toBe­Clo­seTo( number, precision )
toTh­row()
Matchers can be chained with a not between the actual and assertion.
 

jasmine double­s/spies

spyOn( obj, method­_st­ring )
obj.s­tub­bed­.­ca­lls
array
obj.s­tub­bed­.­mo­stR­ece­ntC­all
call object
obj.s­tub­bed.ca­lls­[0]­.­args
array
toHa­veB­een­Cal­led()
toHa­veB­een­Cal­led­With( array )
andC­all­Thr­oug­h()
spy and delegate to real object
andR­etu­rn( value )
andC­all­Fak­e­(fu­nct­ion() { ... })
jasmi­ne.­cre­ate­Spy( id )
jasmi­ne.­cre­ate­Spy­Obj( baseName, methods[] )
jasmi­ne.­any( const­ructor )
               
 

Comments

Thanks.

Thank you! :)

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

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

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

Helpfull cheat sheet, Thank you.

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.

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

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Bacon.js Cheat Sheet
          Polymer.js Cheat Sheet
          Selenium WebDriver Cheat Sheet Cheat Sheet

          More Cheat Sheets by CITguy

          Extending Ruby with C - Part 1 Cheat Sheet
          *nix users and groups Cheat Sheet
          Extending Ruby with C - Part 2 Cheat Sheet