Skip to content

Instantly share code, notes, and snippets.

@golbin
Last active August 29, 2015 14:24
Show Gist options
  • Save golbin/06cbfa408aa11da28fcd to your computer and use it in GitHub Desktop.
Save golbin/06cbfa408aa11da28fcd to your computer and use it in GitHub Desktop.
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);
}
});
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