Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Created August 23, 2011 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsiii/1166089 to your computer and use it in GitHub Desktop.
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
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