Show Menu
Cheatography

jasmine JS testing Cheat Sheet by

DOM-less simple JavaScript testing framework

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 )
               
 

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

          Selenium WebDriver Cheat Sheet Cheat Sheet
          Cypressio Cheat Sheet
          ISTQB Test Automation Engineering 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