summaryrefslogtreecommitdiff
path: root/mocha_test/nextTick.js
blob: b42882233cdf0ce7d4e97c1889b41e3a90442c1e (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
var async = require('../lib');
var expect = require('chai').expect;

describe("nextTick", function () {

    it('basics', function(done){
        var call_order = [];
        async.nextTick(function(){call_order.push('two');});
        call_order.push('one');
        setTimeout(function(){
            expect(call_order).to.eql(['one','two']);
            done();
        }, 50);
    });

    it('nextTick in the browser', function(done){
        if (!process.browser) {
            // skip this test in node
            return done();
        }

        var call_order = [];
        async.nextTick(function(){call_order.push('two');});

        call_order.push('one');
        setTimeout(function(){
            expect(call_order).to.eql(['one','two']);
            done();
        }, 50);
    });

    it("extra args", function (done) {
        async.nextTick(function (a, b, c) {
            expect([a, b, c]).to.eql([1, 2, 3]);
            done();
        }, 1, 2, 3);
    });
});