-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ paratask.usePromise() API for letting the user use his own Promise …
…constructor
- Loading branch information
1 parent
731fc6d
commit 8667489
Showing
6 changed files
with
363 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
This file will cover test cases of using "paratask.usePromise()" functionality for setting | ||
custom/user preferred Promise constructor function | ||
*/ | ||
'use strict'; | ||
|
||
var paratask = require('../lib/index.js'); | ||
var promise = require('../lib/promise.js'); | ||
var bluebird = require('bluebird'); | ||
|
||
|
||
module.exports = { | ||
'calling "paratask.usePromise()" with wrong argument': function (test) { | ||
test.expect(3); | ||
|
||
try { | ||
paratask.usePromise(); | ||
} catch (error) { | ||
test.ok( error instanceof TypeError, 'Empty call triggers a "TypeError"'); | ||
} | ||
|
||
try { | ||
paratask.usePromise({}); | ||
} catch (error) { | ||
test.ok( error instanceof TypeError, 'Called with empty object {} triggers a "TypeError"'); | ||
} | ||
|
||
try { | ||
paratask.usePromise(function () {}); | ||
} catch (error) { | ||
test.ok( error instanceof TypeError, 'Called with empty function "function () {}" triggers a "TypeError"'); | ||
} | ||
|
||
test.done(); | ||
}, | ||
|
||
|
||
'calling "paratask.usePromise()" with valid Promise constructor functions': function (test) { | ||
test.expect(3); | ||
|
||
var task = { | ||
fork: function (resolve) { | ||
resolve(true); | ||
} | ||
}; | ||
|
||
paratask([task]) | ||
.then(function (resolved) { | ||
test.ok( resolved, 'Calling "paratask()" without setting "paratask.usePromise()" should use a default Promise constructor'); | ||
|
||
paratask.usePromise( promise ); | ||
return paratask([task]); | ||
}) | ||
.then(function (resolved) { | ||
test.ok( resolved, 'Calling "paratask()" with set custom Promise constructor'); | ||
|
||
paratask.usePromise( bluebird.Promise ); | ||
return paratask([task]); | ||
}) | ||
.then(function (resolved) { | ||
test.ok( resolved, 'Calling "paratask()" with set "bluebird" Promise constructor'); | ||
test.done(); | ||
}) | ||
} | ||
}; |
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
Oops, something went wrong.