@@ -1735,8 +1735,40 @@ window.jasmine && (function(window) {
1735
1735
* instance of {@link AUTO.$injector $injector} per test, which is then used for
1736
1736
* resolving references.
1737
1737
*
1738
- * See also {@link angular.mock.module module}
1739
1738
*
1739
+ * ## Resolving References (Underscore Wrapping)
1740
+ * Often, we would like to inject a reference once, in a `beforeEach()` block and reuse this
1741
+ * in multiple `it()` clauses. To be able to do this we must assign the reference to a variable
1742
+ * that is declared in the scope of the `describe()` block. Since we would, most likely, want
1743
+ * the variable to have the same name of the reference we have a problem, since the parameter
1744
+ * to the `inject()` function would hide the outer variable.
1745
+ *
1746
+ * To help with this, the injected parameters can, optionally, beenclosing with underscores.
1747
+ * These are ignored by the injector when the reference name is resolved.
1748
+ *
1749
+ * For example, the parameter `_myService_` would be resolved as the reference `myService`.
1750
+ * Since it is available in the function body as _myService_, we can then assign it to a variable
1751
+ * defined in an outer scope.
1752
+ *
1753
+ * ```
1754
+ * // Defined out reference variable outside
1755
+ * var myService;
1756
+ *
1757
+ * // Wrap the parameter in underscores
1758
+ * beforeEach( inject( function(_myService_){
1759
+ * myService = _myService_;
1760
+ * }));
1761
+ *
1762
+ * // Use myService in a series of tests.
1763
+ * it('makes use of myService', function() {
1764
+ * myService.doStuff();
1765
+ * });
1766
+ *
1767
+ * ```
1768
+ *
1769
+ * See also {@link angular.mock.module angular.mock.module}
1770
+ *
1771
+ * ## Example
1740
1772
* Example of what a typical jasmine tests looks like with the inject method.
1741
1773
* <pre>
1742
1774
*
@@ -1773,7 +1805,7 @@ window.jasmine && (function(window) {
1773
1805
* });
1774
1806
*
1775
1807
* </pre>
1776
- *
1808
+ *
1777
1809
* @param {...Function } fns any number of functions which will be injected using the injector.
1778
1810
*/
1779
1811
window . inject = angular . mock . inject = function ( ) {
0 commit comments