42 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
 | 
						|
.l-main-section
 | 
						|
  h2(class="function export") inject
 | 
						|
 | 
						|
  
 | 
						|
  pre.prettyprint
 | 
						|
    code.
 | 
						|
      inject(tokens: List<any>, fn: Function) : FunctionWithParamTokens
 | 
						|
  
 | 
						|
 | 
						|
  p.location-badge.
 | 
						|
    exported from <a href='../test'>angular2/test</a>
 | 
						|
    defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.34/modules/angular2/src/test_lib/test_injector.ts#L161-L194">angular2/src/test_lib/test_injector.ts (line 161)</a>
 | 
						|
 | 
						|
  :markdown
 | 
						|
    Allows injecting dependencies in `beforeEach()` and `it()`.
 | 
						|
    
 | 
						|
    Example:
 | 
						|
    
 | 
						|
    ```
 | 
						|
    beforeEach(inject([Dependency, AClass], (dep, object) => {
 | 
						|
      // some code that uses `dep` and `object`
 | 
						|
      // ...
 | 
						|
    }));
 | 
						|
    
 | 
						|
    it('...', inject([AClass, AsyncTestCompleter], (object, async) => {
 | 
						|
      object.doSomething().then(() => {
 | 
						|
        expect(...);
 | 
						|
        async.done();
 | 
						|
      });
 | 
						|
    })
 | 
						|
    ```
 | 
						|
    
 | 
						|
    Notes:
 | 
						|
    - injecting an `AsyncTestCompleter` allow completing async tests - this is the equivalent of
 | 
						|
      adding a `done` parameter in Jasmine,
 | 
						|
    - inject is currently a function because of some Traceur limitation the syntax should eventually
 | 
						|
      becomes `it('...', @Inject (object: AClass, async: AsyncTestCompleter) => { ... });`
 | 
						|
    
 | 
						|
 | 
						|
 |