Skip to content

Instantly share code, notes, and snippets.

@sbilodeau
Created October 2, 2015 18:35
Show Gist options
  • Save sbilodeau/c55ffa92ccf8eb3b47fd to your computer and use it in GitHub Desktop.
Save sbilodeau/c55ffa92ccf8eb3b47fd to your computer and use it in GitHub Desktop.
(function (global, _it) {
global.it = function(title, callback) {
_it(title, function(done) {
var result = callback();
if(result.then) {
result.then(done).catch(done.fail);
}
else {
done();
}
});
};
})(global||window, it);
@pleblond
Copy link

pleblond commented Oct 2, 2015

(function (global, _it) {

    global.it = function(description, fn, timeout) {

        if(fn.length) {
            return _it(description, fn, timeout);
        }

        return _it(description, function(done) {

            var res = fn();

            if(res && res.then instanceof Function) {
                res.then(done).catch(done.fail);
            } else {
                done();
                return res;
            }
        }, timeout);
    };
})(global||window, it);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment