📜 ⬆️ ⬇️

Test.it v1.1.0 released - what’s next?

Good afternoon Habr.
Yesterday version 1.1.0 was released test.it - a framework for testing js code.
He finally got a functional, the absence of which made it inferior:As well as other trifles.

picture to attract attention
Who doesn’t like a lot of words ? Website where you can see the code in action, GitHub , Wiki

Changjlog



')

New opportunities


Link chain. Addtrace (level) - adds to the test / group trace - the list of lines that led to its execution.
level - sets the number of lines to be displayed (or the depth of the scopes to which the trace will go) .
The method was added at the request of the user vk Denya Tatarinov , with the explanation that this is useful for monitoring a large number of asynchronous calls (tests).
I have a good habit to log every ajax request. more accurate response from the server. and when some kind of crap happens, I would like to know in which line it happened) not to write that man, this is the 45th line in each call. + helps to navigate by code

For this task, the output of only one (current) line is enough, but who knows who will need to track down some confusing code.
Sample and screenshot
(function firstFunction() { (function secondFunction() { (function lastFunction() { test.it(1).addTrace(0); //     test.it(1).addTrace(); //    })(); })(); })(); 
addTrace


Chain preparer .time - adds to the test output the time spent on its execution (or the execution of the function, the result of which was passed to the test)
Please note that this is not a method, but an attribute. Do not put brackets after it!
Sample and screenshot
 test.time.it(someThing()); 
time


.Exclude chain preparer - prevents a test or group from falling on the current level stack. This attribute also does not put brackets after it!
May be useful for asynchronous tests.
Example
 alert(test.exclude.it(someThing).result()); // alert    test.exclude.group('some group',function(){ ... }).done(); //    


Conclusion of individual tests and groups

Finally, all these .group made sense!
.done () - depending on how and where the output was called:


Asynchronous tests


Thanks to the new .done () behavior (and a little .exclude ) , asynchronous tests are now available:
 var a = false; // ,     2  setTimeout(function () {a=true}, 2000) //  ( )   setTimeout(function () { test.group('async tests',function(){ test.it(a).comment('   '); }).comment('async group').done(); //   }, 1000); setTimeout(function () { test.exclude.it(a).comment('  ').done(); //  ,     root }, 3000); 
After ~ 3 seconds in the console will be:
async

Todo


now, in addition to polishing the already done, I set the priority task - a port on node.js and similar languages ​​(?).

Links


The site where you can see the code in action, GitHub , Wiki

PS


While refactoring, I wondered who actually needs test.them and test.types ? In this connection, I want to ask the community a question, what tests do you use most often? What tests do you need in principle?

The survey will show tests only from this framework, but in the comments you can speak about tests in other frameworks, including for other languages.

Source: https://habr.com/ru/post/190200/


All Articles