142
St
startsInvasion / files
startsInvasion / libs / node_modules / bean / support / sink / README.md
1.6 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``` js 12test('should have foo', 1, function() { 13 $.ajax('/foo', function(resp) { 14 ok(resp.stat == '200'); 15 }); 16}); 17``` 18 19Loading a suite of tests 20------------------------ 21 22The 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: 23 24``` js 25sink('my module', function(test, ok, before, after) { 26 before(function () { 27 // run this before every test 28 }); 29 30 after(function () { 31 // run this after every test 32 }); 33 34 test('should have foo', 2, function () { 35 ok(true, 'this is basically true'); 36 ok(1 == 1, 'also true for you math majors'); 37 }); 38}); 39 40sink('another module', function (t, o, b, a) { 41 test('a failure', 1, function () { 42 ok(1 == 2, 'should fail'); 43 }); 44}); 45 46start(); // start all test modules 47``` 48 49Browser support 50--------------- 51 52Any browser that supports JavaScript as well as Headless via command line with Node. (see below) 53 54``` js 55// tests.js 56/** this snippet can be found in src/headless.js */ 57var sink = require('path/to/sink'); 58var start = sink.start; 59sink = sink.sink; 60 61sink('some module', function (test, ok) { 62 // write tests 63}); 64 65sink('another module', function (test, ok) { 66 // write tests 67}); 68 69start(); 70``` 71 72in your terminal 73 74 $ node path/to/my/tests.js 75 76Happy testing!