summaryrefslogtreecommitdiff
path: root/mocha_test/until.js
blob: a738218387977f5e52800c05fbda2401070f6472 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var async = require('../lib');
var expect = require('chai').expect;
var assert = require('assert');

describe('until', function(){
    it('until', function(done) {
        var call_order = [];
        var count = 0;
        async.until(
            function () {
                call_order.push(['test', count]);
                return (count == 5);
            },
            function (cb) {
                call_order.push(['iteratee', count]);
                count++;
                cb(null, count);
            },
            function (err, result) {
                assert(err === null, err + " passed instead of 'null'");
                expect(result).to.equal(5, 'last result passed through');
                expect(call_order).to.eql([
                    ['test', 0],
                    ['iteratee', 0], ['test', 1],
                    ['iteratee', 1], ['test', 2],
                    ['iteratee', 2], ['test', 3],
                    ['iteratee', 3], ['test', 4],
                    ['iteratee', 4], ['test', 5],
                ]);
                expect(count).to.equal(5);
                done();
            }
        );
    });

    it('doUntil', function(done) {
        var call_order = [];
        var count = 0;
        async.doUntil(
            function (cb) {
                call_order.push(['iteratee', count]);
                count++;
                cb(null, count);
            },
            function () {
                call_order.push(['test', count]);
                return (count == 5);
            },
            function (err, result) {
                assert(err === null, err + " passed instead of 'null'");
                expect(result).to.equal(5, 'last result passed through');
                expect(call_order).to.eql([
                    ['iteratee', 0], ['test', 1],
                    ['iteratee', 1], ['test', 2],
                    ['iteratee', 2], ['test', 3],
                    ['iteratee', 3], ['test', 4],
                    ['iteratee', 4], ['test', 5]
                ]);
                expect(count).to.equal(5);
                done();
            }
        );
    });

    it('doUntil callback params', function(done) {
        var call_order = [];
        var count = 0;
        async.doUntil(
            function (cb) {
                call_order.push(['iteratee', count]);
                count++;
                cb(null, count);
            },
            function (c) {
                call_order.push(['test', c]);
                return (c == 5);
            },
            function (err, result) {
                if (err) throw err;
                expect(result).to.equal(5, 'last result passed through');
                expect(call_order).to.eql([
                    ['iteratee', 0], ['test', 1],
                    ['iteratee', 1], ['test', 2],
                    ['iteratee', 2], ['test', 3],
                    ['iteratee', 3], ['test', 4],
                    ['iteratee', 4], ['test', 5]
                ]);
                expect(count).to.equal(5);
                done();
            }
        );
    });
});