Skip to content
titulus edited this page Sep 11, 2013 · 23 revisions

Install

There are some differences between usage testit in different environment like browser or nodejs.

Browser

  • First: add core of framework
<script src='path/to/testit.js'></script>
```
  • Next: add output strategy and set firebugConsole as default printer
<script src='path/to/testit-firebug.js'></script> <script>test.printer(firebugConsole);</script>
```
Of course you can include `test.printer(firebugConsole);` in your tests script.

Hint: add <script> tags to the and of your <body> tag.

btw you can use this construction:

<!-- framework -->
<script src='./test.it.js'></script>
<!-- print to firebug console -->
<script src='./test.it-firebug.js'></script>
<!-- set firebugConsole as default printer  -->
<script>test.printer(firebugConsole);</script>
<!-- your script -->
<script src='./script.js'></script>
<!-- your tests -->
<script src='./tests.js'></script>
<!-- a trick to not worry about the call of test.print() -->
<script>test.print();</script>

Nodejs

  • First: install framework and output module

npm install 'test.it' npm install 'test.it-nodejs' ``` Hint: you can use -g flag to install them globally

  • Second: add core of framework and output module, set it as default printer

test = require('test.it'); nodeConsole = require('test.it-nodejs'); test.printer(nodeConsole); btw you can use this construction:javascript (test = require('test.it')).printer(require('test.it-nodejs')); ``` Info: Output module is not required!

Async

To test the async functional use the following structures

asyncFunction(); // that function will fill asyncVariable and asyncResult

// testing group of tests
setTimeout(function () {
    test.group('async tests',function(){
        test.it(asyncResult);
        test.it(asyncVariable);
    }).print(); // .print() is required to output result
}, 2000); // test group will be launched in 2 seconds

// testing single tests
setTimeout(function () {
     test.it(asyncVariable).print(); // .print() is required to output result
}, 2000); // test will be launched in 2 seconds

Tests and groups in setTimeout function will be run in root scope. For running in some group scope use group nesting.

setTimeout(function () {
    test.group('group name')
        .group('async tests',function(){
            test.it(asyncResult);
            test.it(asyncVariable);
        }).print();
}, 2000);

To prevent pushing results in stack of root use .x or .exclude

// testing group of tests
setTimeout(function () {
    test.x.group('async tests',function(){
        test.it(asyncResult);
        test.it(asyncVariable);
    }).print(); // test group will not be pushed into root stack
}, 2000);

// testing single tests
setTimeout(function () {
     test.exclude.it(asyncVariable).print(); // test will not be pushed into root stack
}, 2000);
Clone this wiki locally