docs: function wrapInScheduler(scheduler, newPromise, globalFn, fnName) {
    return function() {
      var driverError = new Error();
      driverError.stack = driverError.stack.replace(/ +at.+jasminewd.+\n/, '');
  
      function asyncTestFn(fn, description) {
        description = description ? ('("' + description + '")') : '';
        return function(done) {
          var async = fn.length > 0;
          var testFn = fn.bind(this);
  
          scheduler.execute(function schedulerExecute() {
            return newPromise(function(fulfill, reject) {
              function wrappedReject(err) {
                if(err instanceof Error)
                  reject(err);
                else 
                  reject(new Error(err));
              }
              if (async) {
                // If testFn is async (it expects a done callback), resolve the promise of this
                // test whenever that callback says to.  Any promises returned from testFn are
                // ignored.
                var proxyDone = fulfill;
                proxyDone.fail = wrappedReject;
                testFn(proxyDone);
              } else {
                // Without a callback, testFn can return a promise, or it will
                // be assumed to have completed synchronously.
                var ret = testFn();
                if (maybePromise.isPromise(ret)) {
                  ret.then(fulfill, wrappedReject);
                } else {
                  fulfill(ret);
                }
              }
            });
          }, 'Run ' + fnName + description + ' in control flow').then(
            callWhenIdle.bind(null, scheduler, done), function(err) {
              if (!err) {
                err = new Error('Unknown Error');
                err.stack = '';
              }
              err.stack = err.stack + '\nFrom asynchronous test: \n' + driverError.stack;
              callWhenIdle(scheduler, done.fail.bind(done, err));
            }
          );
        };
      }
  
      var description, func, timeout;
      switch (fnName) {
        case 'it':
        case 'fit':
          description = validateString(arguments[0]);
          if (!arguments[1]) {
            return globalFn(description);
          }
          func = validateFunction(arguments[1]);
          if (!arguments[2]) {
            return globalFn(description, asyncTestFn(func, description));
          } else {
            timeout = validateNumber(arguments[2]);
            return globalFn(description, asyncTestFn(func, description), timeout);
          }
          break;
        case 'beforeEach':
        case 'afterEach':
        case 'beforeAll':
        case 'afterAll':
          func = validateFunction(arguments[0]);
          if (!arguments[1]) {
            globalFn(asyncTestFn(func));
          } else {
            timeout = validateNumber(arguments[1]);
            globalFn(asyncTestFn(func), timeout);
          }
          break;
        default:
          throw Error('invalid function: ' + fnName);
      }
    };
  }