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
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
Related Cheat Sheets
More Cheat Sheets by CITguy