You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(test): ability to configure providers on a per-spec basis #5128
Right now, the only way to configure DI in tests is to use beforeEachProvider. I need the ability to configure providers on a per-spec basis for routing (currently I have to create extraneous describe blocks to overcome this limitation).
The inject helper could be extended to include this functionality, for instance.
it('should set up a provider for just one test',inject([A,B],(a,b)=>{// do stuff},()=>[provide(A,{useValue: 'a'}),provide(B,{useClass: BImpl})]));
or
it('should set up a provider for just one test',withProviders(()=>[provide(A,{useValue: 'a'}),provide(B,{useClass: BImpl})]).inject([A,B],(a,b)=>{// do stuff}));
Thoughts? I'm partial to option 2 because the providers come first and it's more explicit what they're doing.
// For nowit('should set up a provider for just one test',withProviders(()=>[provide(A,{useValue: 'a'}),provide(B,{useClass: BImpl})]).inject([A,B],(a,b)=>{// do stuff}));// In the future of TSit('should set up provider for just one test',withProviders(()=>[provide(A,{useValue: 'a'}),provide(B,{useClass: BImpl})]).run(@Inject(A)a, @Inject(B)b)=>{// do stuff}));
it('should set up a provider for just one test', withProviders(
() => [provide(A, {useValue: 'a'}), provide(B, {useClass: BImpl})]
).inject([A, B], (a, b) => {
// do stuff
}));
// In the future of TSit('should set up provider for just one test', withProviders(
() => [provide(A, {useValue: 'a'}), provide(B, {useClass: BImpl})]
).run(@Inject(A) a, @Inject(B) b) => {
// do stuff
}));
—
Reply to this email directly or view it on GitHub #5128 (comment).
Activity
juliemr commentedon Nov 19, 2015
Syntax proposal:
or
Thoughts? I'm partial to option 2 because the providers come first and it's more explicit what they're doing.
btford commentedon Nov 19, 2015
I also like option 2
juliemr commentedon Nov 20, 2015
An additional thing to think about: eventually, when TS supports it, we'd like to be able to do:
I'm not sure if there'd be a nice way to fit per-spec providers in to that.
btford commentedon Nov 21, 2015
I can think of several ways to add providers there, but none of them stick out as particularly nice. :/
juliemr commentedon Dec 2, 2015
What about:
btford commentedon Dec 3, 2015
Works for me. I'm not too picky about the implementation.
On Wed, Dec 2, 2015, 15:13 Julie Ralph [email protected] wrote:
angular-automatic-lock-bot commentedon Sep 8, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.