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 )
to(N­ot)­Con­tain( string )
toBe­Les­sTh­an( number )
toBe­Gre­ate­rTh­an( number )
toBe­Clo­seTo( number, precision )
Matchers can be chained with a not between the actual and assertion.

jasmine double­s/spies

spyOn( obj, method­_st­ring )
call object
toHa­veB­een­Cal­led­With( array )
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

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!



Brian Ledsworth Brian Ledsworth, 13:37 19 Apr 14


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