twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

after-test.js (2147B)


      1 /*global suite, test*/
      2 
      3 var assert = require("assert")
      4     , after = require("../")
      5 
      6 test("exists", function () {
      7     assert(typeof after === "function", "after is not a function")
      8 })
      9 
     10 test("after when called with 0 invokes", function (done) {
     11     after(0, done)
     12 });
     13 
     14 test("after 1", function (done) {
     15     var next = after(1, done)
     16     next()
     17 })
     18 
     19 test("after 5", function (done) {
     20     var next = after(5, done)
     21     , i = 5
     22 
     23     while (i--) {
     24         next()
     25     }
     26 })
     27 
     28 test("manipulate count", function (done) {
     29     var next = after(1, done)
     30     , i = 5
     31 
     32     next.count = i
     33     while (i--) {
     34         next()
     35     }
     36 })
     37 
     38 test("after terminates on error", function (done) {
     39     var next = after(2, function(err) {
     40         assert.equal(err.message, 'test');
     41         done();
     42     })
     43     next(new Error('test'))
     44     next(new Error('test2'))
     45 })
     46 
     47 test('gee', function(done) {
     48     done = after(2, done)
     49 
     50     function cb(err) {
     51         assert.equal(err.message, 1);
     52         done()
     53     }
     54 
     55     var next = after(3, cb, function(err) {
     56         assert.equal(err.message, 2)
     57         done()
     58     });
     59 
     60     next()
     61     next(new Error(1))
     62     next(new Error(2))
     63 })
     64 
     65 test('eee', function(done) {
     66     done = after(3, done)
     67 
     68     function cb(err) {
     69         assert.equal(err.message, 1);
     70         done()
     71     }
     72 
     73     var next = after(3, cb, function(err) {
     74         assert.equal(err.message, 2)
     75         done()
     76     });
     77 
     78     next(new Error(1))
     79     next(new Error(2))
     80     next(new Error(2))
     81 })
     82 
     83 test('gge', function(done) {
     84     function cb(err) {
     85         assert.equal(err.message, 1);
     86         done()
     87     }
     88 
     89     var next = after(3, cb, function(err) {
     90         // should not happen
     91         assert.ok(false);
     92     });
     93 
     94     next()
     95     next()
     96     next(new Error(1))
     97 })
     98 
     99 test('egg', function(done) {
    100     function cb(err) {
    101         assert.equal(err.message, 1);
    102         done()
    103     }
    104 
    105     var next = after(3, cb, function(err) {
    106         // should not happen
    107         assert.ok(false);
    108     });
    109 
    110     next(new Error(1))
    111     next()
    112     next()
    113 })
    114 
    115 test('throws on too many calls', function(done) {
    116     var next = after(1, done);
    117     next()
    118     assert.throws(next, /after called too many times/);
    119 });
    120