Created
August 23, 2011 18:36
-
-
Save jfsiii/1166089 to your computer and use it in GitHub Desktop.
Test something, store the result, do something on success and/or failure, (optional) retest after failure
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
function testSupport(options){ | |
var noop = function(){}; | |
if (!options.name) throw Error('test needs a name'); | |
if (!options.root) options.root = testSupport.results = {}; | |
if (!options.success) options.success = noop; | |
if (!options.failure) options.failure = noop; | |
var run = function(options){ | |
var result = (typeof options.test === 'function') ? options.test(options) : options.test; | |
options.root[options.name] = result; | |
([options.failure, options.success][+result])(options); | |
return result; | |
}; | |
var result = run(options); | |
if (!result && options.retest) result = run(options); | |
return options.root[options.name] = result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment