Created
August 25, 2015 11:37
-
-
Save fatso83/146ba63ac62f9c7eec01 to your computer and use it in GitHub Desktop.
Create a faked Promise to use in testing
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
/** | |
* How to create a Promise I can control | |
* when and if it resolves | |
* @returns {promise, resolve, reject} | |
*/ | |
function promiseStub(){ | |
var result = {}; | |
result.p = new Promise(function(res,rej){ | |
result.resolve = res; | |
result.reject = rej; | |
}) | |
return result; | |
} | |
// test | |
var result = promiseStub(); | |
result.p.then(console.log.bind(console, 'success'),console.error.bind(console, 'failed')) | |
console.clear(); | |
console.assert(result.p instanceof Promise) | |
console.assert(result.resolve instanceof Function) | |
console.assert(result.reject instanceof Function) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment