test.js
1.04 KB
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
'use strict';
var assert = require('assert');
var runAsync = require('./index');
describe('runAsync', function () {
it('run synchronous method', function (done) {
var aFunc = function () {
return 'pass1';
};
runAsync(aFunc, function (val) {
assert.equal(val, 'pass1');
done();
});
});
it('run asynchronous method', function (done) {
var aFunc = function () {
var returns = this.async();
setTimeout(returns.bind(null, 'pass2'), 0);
};
runAsync(aFunc, function (val) {
assert.equal(val, 'pass2');
done();
});
});
it('pass arguments', function (done) {
var aFunc = function (a, b) {
assert.equal(a, 1);
assert.equal(b, 'bar');
return 'pass1';
};
runAsync(aFunc, function (val) {
done();
}, 1, 'bar');
});
it('allow only callback once', function (done) {
var aFunc = function () {
var returns = this.async();
returns();
returns();
};
runAsync(aFunc, function (val) {
done();
});
});
});