Created
June 7, 2013 12:14
-
-
Save bahmutov/625f6cc1b8ddc3c32e45 to your computer and use it in GitHub Desktop.
Testing promises using QUnit
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
QUnit.extend( QUnit, { | |
expectSuccess: function (promise, message) { | |
if (!promise) { | |
QUnit.push(false, 'undefined promise', 'promise object', 'missing a promise'); | |
QUnit.start(); | |
} else { | |
promise.then(function onSuccess(successMessage) { | |
QUnit.push(true, null, null, successMessage); | |
QUnit.start(); | |
}, function onFailure(errorMessage) { | |
QUnit.push(false, 'failed', 'promise to be successful', message + '\n' + errorMessage); | |
QUnit.start(); | |
}); | |
} | |
}, | |
expectFailure: function (promise, message) { | |
if (!promise) { | |
QUnit.push(false, 'undefined promise', 'promise object', 'missing a promise'); | |
QUnit.start(); | |
} else { | |
promise.then(function onSuccess(successMessage) { | |
QUnit.push(false, 'succcess', 'promise to fail', message + '\n' + successMessage); | |
QUnit.start(); | |
}, function onFailure(errorMessage) { | |
QUnit.push(true, null, null, errorMessage); | |
QUnit.start(); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment