
test.it(some) .comment('comment to test') .callback(function(){alert('test has been passed')}) .arguments(); // -> [some] test.group('group', function(){ ... }) .comment('comment to group') .result(); // -> true/false test.group('first group',function(){ ... test.group('second group', function(){ ... }); ... }); test.group('first group').group('second group',function(){ ... }); 
console.log( test.typeof(1) ,test.typeof("text") ,test.typeof([1,2,3]) ,test.typeof({a:1,b:2}) ,test.typeof() ,test.typeof(document) ,test.typeof(document.getElementsByTagName("body")) ,test.typeof(window) ,test.typeof(/yes it is RegExp/) // and many many more ... ); test.typeof () - determines the type of the value passed to it.
(function firstFunction() { (function secondFunction() { (function lastFunction() { console.log(test.trace()); })(); })(); })(); test.trace () - returns a list (compiled into strings separated by "\ n") lines of code that were executed to call this method.
var Family = { name: "Desiderio", pet: { type: "dog", name: "google" }, members: [ { name: "Titulus", age: 23 }, { name: "Dude", age: Infinity } ] } var myIQ = 100; var Nothing; I think there should be no questions about this code. test.it("hello world"); test.done(); test.it (value) - creates a new test, checking value for non-falsity.


test.it(2+2==5) .comment("i badly taught algebra at school"); .comment (text) - adds a comment to the test / group in whose chain it was called. At the same time continuing the chain, but more on that later. test.it(2+2==5).comment("i badly taught algebra at school"); But, for cases with longer chains, writing to the bar is more convenient and clearer.
test.it(Infinity>Infinity-1) .comment("philosophically is not it?"); You can think about this expression over a glass of coffee, we are here for another gathered. The test result looks like the result of the previous one, which is obvious.
test.it(myIQ,"genious") .comment("is I'm genious?"); test.it(myIQ,(1+10)*12 - 34 + 5*5*5 - 123) .comment("check my IQ to be a normal"); test.it (value1, value2) - checks the equality of the two values passed to it.
if (test.it(Family) .comment("Is Family exist? Is it not empty?") .result()) { console.info("by if: ","Yep! Here it is!"); } else { console.warn("by if: ","ALARM! there are no Family"); } .result () - ends the chain and returns the test result.
test.it(Nothing) .comment("Is Nothing exist? Is it not empty?") .callback( function(){console.info("by callback: ","Yep! Here it is!");} ,function(){console.warn("by callback: ","ALARM! there are no Nothing");}); .callback (function () {/ * funcIfpass * /} [, function () {/ * funcIffail * /} [, function () {/ * funcIferror * /}]]) - performs one of three functions, depending on result of passing the test or group. At the same time continuing the chain.
test.group("Empty group",function(){}); test.group (name, function () {...}) - creates a new group or refers to an existing one , and fills it with tests that are in the function passed in the second argument.
test.group('Family tests',function(){ test.it(Family.name,"Zukerberg") .comment("Are we test Zukerberg's family?"); test.it(Family.name,"Desiderio") .comment("Or Desiderio's?"); }).comment("unite!"); You see - nothing complicated!
test.group("Family tests",function(){ test.it(Family.pet) .comment("Do we have a pet?") .callback(function(){ // I add test in your test, so you can test while you testing test.it(Family.pet,{type:"dog", name:"google"}) .comment("Is it right pet?"); }); test.it(Family.house) .comment("Do we have a House?") .callback(function(){ // next test will not be executed test.it(Family.pet,{type:"Huge", color:"green"}) .comment("Is it right House?"); }); }); Considering the past 2 tests in this group and, described just now, 4 more tests, in total there will be = 5 (sic!). You can check on the calculator.
test.them([Family.pet, Family.members]) .comment("There must be memebers with pet, to call it a 'Family'"); test.types([Family.pet.name, Family.name],"string") .comment("Is names are string type"); test.them (values) is an analogue of test.it (value) , only takes an array as the first argument, in which it already checks elements for non-false.
var numberOfMembers = test.type(Family.members,"Array") .comment("Is it a several members, nor a single member?") .arguments()[0].length; test.it(numberOfMembers>5) .comment("Is it big family?"); .arguments () - ends the call chain and returns the arguments passed to the test ( not to the group! ).
test.group("Members age",function(){ for (i=0;i<numberOfMembers;i++) { test.it(Family.members[i].age>25) .comment("Is "+Family.members[i].name+" older then 25?"); } }); 
test.it() .comment("yep, here is error"); Such code will lead to an error, because test.it () expects to receive from 1 to 2 arguments.

test.group("here comes strange tests").group("Members age",function(){ test.it("bye") .comment("good"); }); test.group (name) - returns a link to the group, after which it can be used as the beginning of a chain, to add a new group of tests, or to add tests to an already existing subgroup.
console.log( // look how do test.typeof() work test.typeof(1) ,test.typeof("text") ,test.typeof([1,2,3]) ,test.typeof({a:1,b:2}) ,test.typeof() ,test.typeof(document) ,test.typeof(document.getElementsByTagName("body")) ,test.typeof(window) ,test.typeof(/yes it is RegExp/)); (function firstFunction() { // look how do test.trace() work (function secondFunction() { (function lastFunction() { console.log(test.trace()); })(); })(); })(); var Family = { // Here some complex object name: "Desiderio", pet: { type: "dog", name: "google" }, members: [ { name: "Titulus", age: 23 }, { name: "Dude", age: Infinity } ] } var myIQ = 100; // and value var Nothing; // and empty value test.it("hello world"); // Let"s add some simple tests test.it(2+2==5).comment("i badly taught algebra at school"); // with comment test.it(Infinity>Infinity-1).comment("philosophically is not it?"); // with expression // check equalence test.it(myIQ,"genious").comment("is I'm genious?"); test.it(myIQ,(1+10)*12 - 34 + 5*5*5 - 123).comment("check my IQ to be a normal"); // try some chain staff if (test.it(Family).comment("Is Family exist? Is it not empty?").result()) { console.info("by if: ","Yep! Here it is!"); } else { console.warn("by if: ","ALARM! there are no Family"); } // do it again in better way test.it(Nothing).comment("Is Nothing exist? Is it not empty?").callback( function(){console.info("by callback: ","Yep! Here it is!");} ,function(){console.warn("by callback: ","ALARM! there are no Nothing");}); test.group("Empty group",function(){}); // try to make a group test.group('Family tests',function(){ // let's unite it! test.it(Family.name,"Zukerberg").comment("Are we test Zukerberg's family?"); test.it(Family.name,"Desiderio").comment("Or Desiderio's?"); }).comment("unite!"); test.group("Family tests",function(){ // and add some test after test.it(Family.pet).comment("Do we have a pet?") .callback(function(){ // I add test in your test, so you can test while you testing test.it(Family.pet,{type:"dog", name:"google"}).comment("Is it right pet?"); }); test.it(Family.house).comment("Do we have a House?") .callback(function(){ // next test will not be executed test.it(Family.pet,{type:"Huge", color:"green"}).comment("Is it right House?"); }); }); test.group("here comes strange tests",function(){ // test existance of most important Family properties test.them([Family.pet, Family.members]) .comment("There must be memebers with pet, to call it a 'Family'"); // test types of names test.types([Family.pet.name, Family.name],"string") .comment("Is names are string type"); // here some magic var numberOfMembers = test.type(Family.members,"Array") .comment("Is it a several members, nor a single member?") .arguments()[0].length; test.it(numberOfMembers>5).comment("Is it big family?"); // So if we know how many members there, lets check their age test.group("Members age",function(){ for (i=0;i<numberOfMembers;i++) { test.it(Family.members[i].age>25) .comment("Is "+Family.members[i].name+" older then 25?"); } test.it().comment("yep, here is error"); // add some error to see the trace }); }); // add final test deep in group test.group("here comes strange tests").group("Members age",function(){ test.it("bye").comment("good"); }); test.done(); 
{ "type": "group", "name": "root", "time": 0, "result": { "pass": 0, "fail": 0, "error": 0, "total": 0 }, "stack": [] } Source: https://habr.com/ru/post/189216/
All Articles