diff options
| author | Misko Hevery | 2012-01-12 11:06:10 -0800 | 
|---|---|---|
| committer | Misko Hevery | 2012-01-12 13:40:07 -0800 | 
| commit | d648d709f3edcac56132e9e2a84a0fc65f5b48ac (patch) | |
| tree | ac0ba5763838a4f4b880dc72f0cbcedc1b7abc05 /src/angular-mocks.js | |
| parent | 9a8dbfef5151e8e92dc010a597b670e7687ebe9b (diff) | |
| download | angular.js-d648d709f3edcac56132e9e2a84a0fc65f5b48ac.tar.bz2 | |
refactor(module): strict separation between module-config / app-runtime
Diffstat (limited to 'src/angular-mocks.js')
| -rw-r--r-- | src/angular-mocks.js | 52 | 
1 files changed, 46 insertions, 6 deletions
diff --git a/src/angular-mocks.js b/src/angular-mocks.js index f70731d3..d2dbb114 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -935,16 +935,56 @@ window.jstestdriver && (function(window) {   * @return a method   */  window.jasmine && (function(window) { -  window.inject = function () { + +  function getCurrentSpec() { +    return jasmine.getEnv().currentSpec; +  } + +  function isSpecRunning() { +    var spec = getCurrentSpec(); +    return spec && spec.queue.running; +  } + +  window.module = function() { +    var moduleFns = Array.prototype.slice.call(arguments, 0); +    var stack = Error('Declaration Location').stack; +    return isSpecRunning() ? workFn() : workFn; +    ///////////////////// +    function workFn() { +      var spec = getCurrentSpec(); +      if (spec.$injector) { +        throw Error('Injector already created, can not register a module!'); +      } else { +        var modules = spec.$modules || (spec.$modules = []); +        angular.forEach(moduleFns, function(module) { +          modules.push(module); +        }); +      } +    } +  }; +  window.inject = function() {      var blockFns = Array.prototype.slice.call(arguments, 0); -    return function() { -      var injector = this.$injector; +    var stack = Error('Declaration Location').stack; +    return isSpecRunning() ? workFn() : workFn; +    ///////////////////// +    function workFn() { +      var spec = getCurrentSpec(); +      var modules = spec.$modules || []; +      modules.unshift('ngMock'); +      modules.unshift('ng'); +      var injector = spec.$injector;        if (!injector) { -        injector = this.$injector = angular.injector('ng', 'ngMock'); +        injector = spec.$injector = angular.injector(modules);        } +      console.log('inject', modules)        for(var i = 0, ii = blockFns.length; i < ii; i++) { -        injector.invoke(this, blockFns[i]); +        try { +          injector.invoke(blockFns[i] || angular.noop, this); +        } catch (e) { +          if(e.stack) e.stack +=  '\n' + stack; +          throw e; +        }        } -    }; +    }    }  })(window);  | 
