-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support options.multiArgs and options.withCallback (#27)
- Loading branch information
1 parent
a9531d6
commit 9a74a1c
Showing
3 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
var assert = require('assert') | ||
|
||
var promisify = require('..') | ||
|
||
var setImmediate = global.setImmediate || function (fn) { | ||
process.nextTick(fn) | ||
} | ||
|
||
describe('options', function () { | ||
describe('.withCallback', function () { | ||
function fn(cb) { | ||
cb(null, true) | ||
} | ||
|
||
it('promise', function () { | ||
return promisify(fn, { withCallback: true })().then(function (val) { | ||
assert.equal(val, true) | ||
}) | ||
}) | ||
|
||
it('callback', function (done) { | ||
return promisify(fn, { withCallback: true })(function (err, val) { | ||
assert.equal(val, true) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('.multiArgs', function () { | ||
function fn(cb) { | ||
cb(null, 1, 2, 3) | ||
} | ||
|
||
it('default to true', function () { | ||
return promisify(fn)().then(function (values) { | ||
assert.deepEqual(values, [1, 2, 3]) | ||
}) | ||
}) | ||
|
||
it('set to false', function () { | ||
return promisify(fn, { multiArgs: false })().then(function (value) { | ||
assert.equal(value, 1) | ||
}) | ||
}) | ||
|
||
it('set to array', function () { | ||
return promisify(fn, { multiArgs: [ 'one', 'tow', 'three' ] })().then(function (value) { | ||
assert.deepEqual(value, { | ||
one: 1, | ||
tow: 2, | ||
three: 3 | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |