angular-cn/public/docs/js/latest/api/test/inject-function.jade

44 lines
1.2 KiB
Plaintext
Raw Normal View History

2015-04-19 13:53:18 -07:00
.l-main-section
h2(class="function export") inject
2015-06-01 22:51:00 -07:00
pre.prettyprint
code.
inject(tokens: List<any>, fn: Function) : FunctionWithParamTokens
2015-04-19 13:53:18 -07:00
2015-04-22 08:06:51 -07:00
p.location-badge.
2015-06-01 22:51:00 -07:00
exported from <a href='../test'>angular2/test</a>
defined in <a href="https://github.com/angular/angular/tree/master/modules/angular2/src/test_lib/test_injector.ts#L135-L169">angular2/src/test_lib/test_injector.ts (line 135)</a>
2015-04-19 13:53:18 -07:00
: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) => { ... });`
2015-06-01 22:51:00 -07:00
@param {Array} tokens
@param {Function} fn
2015-04-19 13:53:18 -07:00