xonecas.io
142
St

startsInvasion / files

startsInvasion / libs / node_modules / bonzo / build / sink / README.md

1.7 KB
1Sink Test
2---------
3
4An Asynchronous JavaScript Unit Testing Framework designed to run headless, or in the browser.
5
6Sink test is used to test JavaScript that is run asynchronously whereby you tell the test a number of expectations and Sink will tell you if they each pass successfully.
7
8How to write a Sink test
9------------------------
10
11    test('should have foo', 1, function() {
12      $.ajax('/foo', function(resp) {
13        ok(resp.stat == '200');
14      });
15    });
16
17Loading a suite of tests
18------------------------
19
20The above example illustrates the basic syntax of a single test, however loading your tests is done via the *sink* module which exports the test and ok methods. See the example below:
21
22    sink('my module', function(test, ok, before, after) {
23      before(function () {
24        // run this before every test
25      });
26
27      after(function () {
28        // run this after every test
29      });
30
31      test('should have foo', 2, function() {
32        ok(true, 'this is basically true');
33        ok(1 == 1, 'also true for you math majors');
34      });
35    });
36
37    sink('another module', function (t, o, b, a) {
38      test('a failure', 1, function () {
39        ok(1 == 2, 'should fail');
40      });
41    });
42
43    start(); // start all test modules
44
45Browser support
46---------------
47
48Any browser that supports JavaScript as well as Headless via command line with Node. (see below)
49
50    // tests.js
51    /** this snippet can be found in src/headless.js */
52    var sink = require('path/to/sink');
53    var start = sink.start;
54    sink = sink.sink;
55
56    sink('some module', function (test, ok) {
57      // write tests
58    });
59
60    sink('another module', function (test, ok) {
61      // write tests
62    });
63
64    start();
65
66in your terminal
67
68    % node path/to/my/tests.js
69
70Happy testing!