Skip to content

Commit 2d25126

Browse files
author
tunnckoCore
committed
fix(non-strict): fix a bug in non-strict mode
Closes #13
1 parent 3222afe commit 2d25126

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ module.exports = function isAsyncFunction (fn, names, strict) {
5656
names = utils.isArray(names) ? names : utils.arrayify(names)
5757
names = names.length ? names : utils.callbackNames
5858

59-
var idx = utils.arrIncludes(utils.fnArgs(fn), names)
59+
var idx = utils.arrIncludes(names, utils.fnArgs(fn))
6060
return strict ? Boolean(idx) : idx
6161
}

test.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ test('should accept second argument `names` to be boolean true', function (done)
6767

6868
test('should have non-strict mode to return index', function (done) {
6969
var res = isAsyncFunction(fs.stat, null, false)
70-
test.strictEqual(typeof res, 'number')
71-
test.strictEqual(res, 1)
70+
71+
// fs.stat uses `callback` as callbacka rgument
72+
test.strictEqual(typeof res, 'boolean')
73+
test.strictEqual(res, true)
74+
75+
// `next` is 6th item in `common-callback-names`
76+
function fn (foo, bar, next) {}
77+
function fn2 (foo, cb_) {}
78+
test.strictEqual(isAsyncFunction(fn, null, false), 5)
79+
test.strictEqual(isAsyncFunction(fn2, false), 3)
7280
done()
7381
})
7482

0 commit comments

Comments
 (0)