Cheatography
https://cheatography.com
DOM-less simple JavaScript testing framework
jasmine statements
describe( label, function(){ ... }) group tests together
|
it( label, function(){ ... }) label individual test
|
expect( actual ) used to compare against expected values
|
beforeEach(function(){ ... }) run prior to each it in the describe
|
afterEach(function() { ... }) run after each it in the describe
|
xdescribe( label, function(){ ... }) skip section ( note the x )
|
xit( label, function(){ ... }) skip test ( note the x )
|
|
|
jasmine matchers
to(Not)Be( null | true | false ) |
to(Not)Equal( value ) |
to(Not)Match( regex | string ) |
toBeDefined() |
toBeUndefined() |
toBeNull() |
toBeTruthy() |
toBeFalsy() |
to(Not)Contain( string ) |
toBeLessThan( number ) |
toBeGreaterThan( number ) |
toBeNaN() |
toBeCloseTo( number, precision ) |
toThrow() |
Matchers can be chained with a not between the actual and assertion.
|
|
jasmine doubles/spies
spyOn( obj, method_string ) |
obj.stubbed.calls array
|
obj.stubbed.mostRecentCall call object
|
obj.stubbed.calls[0].args array
|
toHaveBeenCalled() |
toHaveBeenCalledWith( array ) |
andCallThrough() spy and delegate to real object
|
andReturn( value ) |
andCallFake(function() { ... }) |
jasmine.createSpy( id ) |
jasmine.createSpyObj( baseName, methods[] ) |
jasmine.any( constructor ) |
|
Created By
Metadata
Favourited By
and 8 more ...
Comments
Brian Ledsworth 13:37 19 Apr 14
Thanks.
Elder 09:34 31 Oct 14
Thank you! :)
Vinny 12:05 11 Nov 14
Can you create a cheat sheet for Jasmine 2.x?
Monisgnor 09:10 20 Nov 14
The list is not complete. There are no "ddescribe", "iit" and perhaps other methods.
Troy 12:17 8 Jun 15
"ddescribe" and "iit" were renamed to "fdescribe" and "fit". (The f standing for focus)
Sofyan 09:57 4 Aug 15
Helpfull cheat sheet, Thank you.
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 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
Related Cheat Sheets
More Cheat Sheets by CITguy