-
Notifications
You must be signed in to change notification settings - Fork 10
API
##Contents
##Basic properties
Basic API availible through test object
###Methods:
-
test.done()- outputs the result to the console.This method must be a last line of code in your tests.
example:
var a = 1; var b = 2; test.it(a+b === 3); test.done(); // outputs result
####tests Tests is basic functional of test.it framework.
They all:
- check some received value or values;
- can receive exact number of arguments (return an error instead of the value if not);
- add their result in the current level stack.
There are list of all availible tests (v.1.0.0):
-
test.it( value )- checksvaluefor non-false value.Simplify it looks like:
javascript if ( value ) {return 'pass'} else {return 'fail'}So everyvaluewhich will passiftest - will passtest.it( value ). ```javascript // Next tests will pass test.it( 1 ); test.it( 'text' ); test.it( true ); test.it( window ); test.it( alert ); test.it( 2+2 === 4 ); var a = 10; test.it( a > 5 );
// Next tests will fail test.it( 0 ); test.it( '' ); test.it( false ); test.it( 2+2 === 5 ); var a = 3; test.it( a > 5 ); test.it( null ); test.it( NaN );
// Next line will return error test.it( ); test.it( 1, 2, 3 );
// Next line will throw the ReferenceError and will not be executed test.it( myNotDefinedVariable ); test.it( myNotDefinedFunction() ); ```
-
test.it( value1, value2 )- checks the equality betweenvalue1&value2.There are not simply
value1 == value2. But useddeepCompare()function from here. It can compare any type of values, but obviously they must be of the same type.
// Next tests will pass test.it( 5, 5 ) test.it( 'text', 'text' ) test.it( [1,2,3], [1,2,3] ) test.it( {a:1,b:2}, {a:1,b:2} )
// Next tests will fail test.it( 5, 1 ) test.it( 'text', 'line' ) test.it( '10', 10 ) test.it( [1,2,3], [3,2,1] ) test.it( {a:1,b:2}, {a:1,b:2,c:3} ) ```
-
test.them( values )- checks for non-false all values in anvalues.Is similar to
test.it( value )but check for non-false more then 1 values, but they must be contained invaluesarray.
// Next tests will pass test.them( [1,'text',true,window,alert] )
// Next tests will fail test.them( [1,'text',true,window,alert,false] )
// Next line will return error test.them( ) test.them( 1 ) test.them( 1, 2 ) test.them( [1,2], 2 ) ```
-
test.type( value, type )- checks the type (function,object, ...) of anvalue.Uses
test.typeof()function - more powerful then commontypeof(). It recognizesarray,boolean,date,error(evalerror,rangeerror,referenceerror,syntaxerror,typeerror,urierror),function,nan&number,object,regexp,string,window,dom,nodelist.There no matter case of type name. Feel free to use 'String' or 'string' or 'StRiNg' etc.
// Next tests will pass test.type( 1, 'number' ) test.type( 'text', 'String' ) test.type( alert, 'function' )
// Next tests will pass test.type( 'text', 'number' ) test.type( alert, 'String' ) test.type( 1, 'function' )
// Next line will return error test.type( ) test.type( 1 ) test.type( 1, 2 ) test.type( 1, 'myType' ) test.type( 1, 'number', 3 ) ```
-
test.types( values [, type] )- checks the equality between types of all values invalues. Iftypedefined - types of values will be compared with it.Is similar to
test.type( value, type )but check types more then 1 values, but they must be contained invaluesarray.
// Next tests will pass test.types( [1,2,3,new Number()] ) test.types( [1,2], 'number' ) test.types( ['asd','dsa'], 'string' )
// Next tests will fail test.types( [1,2,'text'] ) test.types( ['asd','dsa'], 'number' )
// Next line will return error test.types( ) test.types( 1 ) test.types( 1, 2 ) test.types( 1, 'number' ) test.types( [1,2], 'myType' ) test.types( [1,2], 'number', 3 ) ``` ###groups Groups are extrimly useful tool, which allows multi-level combining tests.
-
test.group( name, function(){ ... } )- made new group.If group already exist on current level, extend it.
// will make group with group in it test.group('first group',function(){ // ... here goes first tests test.group('group in first group',function(){ // ... here goes second tests }); // ... here goes third tests });
// add tests to group 'first group'
test.group('first group',function(){
// ... here goes fourth tests
});
Code above is similar to:javascript
// will make group with group in it
test.group('first group',function(){
// ... here goes first tests
test.group('group in first group',function(){
// ... here goes second tests
});
// ... here goes third tests
// ... here goes fourth tests
});
```
-
test.group( name )- returntestobject - to provide chaining, with link to group by it's name - to provide nesting.Provide transit to next-level group
// will make group with group in it test.group('first group',function(){ // ... here goes first tests test.group('group in first group',function(){ // ... here goes second tests }); // ... here goes third tests });
// add tests to group 'group in first group'
test.group('first group').group('group in first group',function(){
// ... here goes fourth tests
});
Code above is similar to:javascript
// will make group with group in it
test.group('first group',function(){
// ... here goes first tests
test.group('group in first group',function(){
// ... here goes second tests
// ... here goes fourth tests
});
// ... here goes third tests
});
```
More about groups nesting.
Groups throw error if recieved 0 or more then 2 arguments, or if there are 1 arguments, with non existing name:
test.group( );
test.group('wrong group',function(){
test.it(true);
},3);
test.group('non existing group')###Attributes:
-
test.root- return zero-level group.All result will get in it. Any type of output bases on it.
Empty root has structure:
{
type: "group",
name: "root",
status: undefined,
time: 0,
result: {
pass: 0,
fail: 0,
error: 0,
total: 0
},
stack: []
}
```
Every test located outside groups and first-level groups will get into root.stack.
When any test/group get into any stack, `result` counters and `status` of current and all previous levels (till `root`) are updates. But counters of `result` mean number of test/groups in current level only.
##Chaining Chain - set of functions, starts from Chain-opener, continue by Chain-links and ended with Chain-closers.
chainOpener().chainLink().chainLink().chainCloser();
// or
chainOpener()
.chainLink()
.chainLink()
.chainCloser();###Chain-openers
###Chain-links
-
.comment( text )- add comment to test/groupIf there are more then one
.comment( text )in chain - only last will be used.
test.group('first group',function(){ test.it(true) .comment('test with true argument'); }).comment('group with only one test'); ```
-
.callback( function(){ /* funcIfpass */}[, function(){ /* funcIffail */}[, function(){ /* funcIferror */}]])- will execute funcIfpass if test/group pass, funcIffail if it failed, funcIferror if it cause error.
###Chain-closers
-
.result()- return result of test/group -
.arguments()- return single argument or array of arguments from test (not from group!)
##features
