Last active
August 29, 2015 14:24
-
-
Save golbin/06cbfa408aa11da28fcd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var nodeunit = require('nodeunit'), | |
| promiseFuncs = require(__dirname + '/../index'); | |
| exports['Promise unit test'] = nodeunit.testCase({ | |
| 'success from Q': function (test) { | |
| promiseFuncs.success() | |
| .then(test.ok) | |
| .fail(console.log) | |
| .done(test.done); | |
| }, | |
| 'reject from Q': function (test) { | |
| promiseFuncs.reject() | |
| .then(function () { | |
| test.ok(false); | |
| }) | |
| .fail(function (err) { | |
| test.ok(true); | |
| }) | |
| .done(test.done); | |
| }, | |
| 'exception within Q': function (test) { | |
| promiseFuncs.exception() | |
| .then(function () { | |
| test.ok(false); | |
| }) | |
| .fail(function (err) { | |
| test.ok(true); | |
| }) | |
| .done(test.done); | |
| } | |
| }); |
This file contains hidden or 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
| var Q = require('q'); | |
| module.exports = { | |
| success: function () { | |
| return Q.resolve(true); | |
| }, | |
| reject: function () { | |
| return Q.reject(false); | |
| }, | |
| exception: function () { | |
| return Q.fcall(function () { | |
| throw new Error(); | |
| }); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment