@@ -1892,8 +1892,40 @@ angular.mock.clearDataCache = function() {
1892
1892
* instance of {@link AUTO.$injector $injector} per test, which is then used for
1893
1893
* resolving references.
1894
1894
*
1895
- * See also {@link angular.mock.module module}
1896
1895
*
1896
+ * ## Resolving References (Underscore Wrapping)
1897
+ * Often, we would like to inject a reference once, in a `beforeEach()` block and reuse this
1898
+ * in multiple `it()` clauses. To be able to do this we must assign the reference to a variable
1899
+ * that is declared in the scope of the `describe()` block. Since we would, most likely, want
1900
+ * the variable to have the same name of the reference we have a problem, since the parameter
1901
+ * to the `inject()` function would hide the outer variable.
1902
+ *
1903
+ * To help with this, the injected parameters can, optionally, beenclosing with underscores.
1904
+ * These are ignored by the injector when the reference name is resolved.
1905
+ *
1906
+ * For example, the parameter `_myService_` would be resolved as the reference `myService`.
1907
+ * Since it is available in the function body as _myService_, we can then assign it to a variable
1908
+ * defined in an outer scope.
1909
+ *
1910
+ * ```
1911
+ * // Defined out reference variable outside
1912
+ * var myService;
1913
+ *
1914
+ * // Wrap the parameter in underscores
1915
+ * beforeEach( inject( function(_myService_){
1916
+ * myService = _myService_;
1917
+ * }));
1918
+ *
1919
+ * // Use myService in a series of tests.
1920
+ * it('makes use of myService', function() {
1921
+ * myService.doStuff();
1922
+ * });
1923
+ *
1924
+ * ```
1925
+ *
1926
+ * See also {@link angular.mock.module angular.mock.module}
1927
+ *
1928
+ * ## Example
1897
1929
* Example of what a typical jasmine tests looks like with the inject method.
1898
1930
* <pre>
1899
1931
*
@@ -1930,7 +1962,7 @@ angular.mock.clearDataCache = function() {
1930
1962
* });
1931
1963
*
1932
1964
* </pre>
1933
- *
1965
+ *
1934
1966
* @param {...Function } fns any number of functions which will be injected using the injector.
1935
1967
*/
1936
1968
window . inject = angular . mock . inject = function ( ) {
0 commit comments