@@ -36,6 +36,10 @@ export class TestInjector {
3636 }
3737
3838 execute ( fn : FunctionWithParamTokens ) : any {
39+ var additionalProviders = fn . additionalProviders ( ) ;
40+ if ( additionalProviders . length > 0 ) {
41+ this . addProviders ( additionalProviders ) ;
42+ }
3943 if ( ! this . _instantiated ) {
4044 this . createInjector ( ) ;
4145 }
@@ -119,6 +123,22 @@ export function inject(tokens: any[], fn: Function): FunctionWithParamTokens {
119123 return new FunctionWithParamTokens ( tokens , fn , false ) ;
120124}
121125
126+ export class InjectSetupWrapper {
127+ constructor ( private _providers : ( ) => any ) { }
128+
129+ inject ( tokens : any [ ] , fn : Function ) : FunctionWithParamTokens {
130+ return new FunctionWithParamTokens ( tokens , fn , false , this . _providers ) ;
131+ }
132+
133+ injectAsync ( tokens : any [ ] , fn : Function ) : FunctionWithParamTokens {
134+ return new FunctionWithParamTokens ( tokens , fn , true , this . _providers ) ;
135+ }
136+ }
137+
138+ export function withProviders ( providers : ( ) => any ) {
139+ return new InjectSetupWrapper ( providers ) ;
140+ }
141+
122142/**
123143 * Allows injecting dependencies in `beforeEach()` and `it()`. The test must return
124144 * a promise which will resolve when all asynchronous activity is complete.
@@ -141,8 +161,13 @@ export function injectAsync(tokens: any[], fn: Function): FunctionWithParamToken
141161 return new FunctionWithParamTokens ( tokens , fn , true ) ;
142162}
143163
164+ function emptyArray ( ) : Array < any > {
165+ return [ ] ;
166+ }
167+
144168export class FunctionWithParamTokens {
145- constructor ( private _tokens : any [ ] , private _fn : Function , public isAsync : boolean ) { }
169+ constructor ( private _tokens : any [ ] , private _fn : Function , public isAsync : boolean ,
170+ public additionalProviders : ( ) => any = emptyArray ) { }
146171
147172 /**
148173 * Returns the value of the executed function.
0 commit comments