Show Menu

jasmine JS testing Cheat Sheet by

DOM-less simple JavaScript testing framework
javascript     testing     framework     jasmine     js

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 )

Download the jasmine JS testing Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/citguy_jasmine-js-testing.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

Like this cheat sheet? Check out our sponsors!

Readable.io is a collection of tools to make your writing better. More readable content means higher conversion rates and better reader engagement. Measure website and document readability, measure keyword density and more!

Click Here To Get Started!

 

Comments

Brian Ledsworth Brian Ledsworth, 13:37 19 Apr 14

Thanks.

Elder Elder, 09:34 31 Oct 14

Thank you! :)

Vinny Vinny, 12:05 11 Nov 14

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

Monisgnor Monisgnor, 09:10 20 Nov 14

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

Troy Troy, 12:17 8 Jun 15

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

Sofyan Sofyan, 09:57 4 Aug 15

Helpfull cheat sheet, Thank you.

Karan Karan, 10:52 16 Oct 15

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.

Doug Doug, 10:02 22 Oct 15

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