Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test promises with promises-aplus-tests
var promisesAplusTests = require("promises-aplus-tests");
var Promise = require("promise");
var adapter = {
resolved: function(value) {
return new Promise(function(resolve) {
try {
resolve(value);
}
catch (e) {
console.error("Exception resolving in 'resolved' adapter method");
}
});
},
rejected: function(reason) {
return new Promise(function(resolve, reject) {
try {
reject(reason);
}
catch (e) {
console.error("Exception rejecting in 'reject' adapter method");
}
});
},
deferred: function() {
var deferred = {};
var p = new Promise(function(resolve, reject) {
deferred.resolve = function(value) {
try {
resolve(value);
}
catch (e) {
console.error("Exception resolving in 'deferred.promise' adapter method");
}
};
deferred.reject = function(reason) {
try {
reject(reason);
}
catch (e) {
console.error("Exception rejecting in 'deferred.promise' adapter method");
}
};
});
deferred.promise = p;
return deferred;
}
};
promisesAplusTests(adapter, function (err) {
console.log("Failures: " + err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment