@@ -16,13 +16,15 @@ import {
16
16
Directive ,
17
17
InjectFlags ,
18
18
InjectionToken ,
19
+ InjectOptions ,
19
20
Injector ,
20
21
NgModule ,
21
22
NgZone ,
22
23
Pipe ,
23
24
PlatformRef ,
24
25
ProviderToken ,
25
26
Type ,
27
+ ɵconvertToBitFlags as convertToBitFlags ,
26
28
ɵflushModuleScopingQueueAsMuchAsPossible as flushModuleScopingQueueAsMuchAsPossible ,
27
29
ɵgetUnknownElementStrictMode as getUnknownElementStrictMode ,
28
30
ɵgetUnknownPropertyStrictMode as getUnknownPropertyStrictMode ,
@@ -87,7 +89,14 @@ export interface TestBed {
87
89
88
90
compileComponents ( ) : Promise < any > ;
89
91
92
+ inject < T > ( token : ProviderToken < T > , notFoundValue : undefined , options : InjectOptions & {
93
+ optional ?: false
94
+ } ) : T ;
95
+ inject < T > ( token : ProviderToken < T > , notFoundValue : null | undefined , options : InjectOptions ) : T | null ;
96
+ inject < T > ( token : ProviderToken < T > , notFoundValue ?: T , options ?: InjectOptions ) : T ;
97
+ /** @deprecated use object-based flags (`InjectOptions`) instead. */
90
98
inject < T > ( token : ProviderToken < T > , notFoundValue ?: T , flags ?: InjectFlags ) : T ;
99
+ /** @deprecated use object-based flags (`InjectOptions`) instead. */
91
100
inject < T > ( token : ProviderToken < T > , notFoundValue : null , flags ?: InjectFlags ) : T | null ;
92
101
93
102
/** @deprecated from v9.0.0 use TestBed.inject */
@@ -290,10 +299,19 @@ export class TestBedImpl implements TestBed {
290
299
return TestBedImpl . INSTANCE . overrideProvider ( token , provider ) ;
291
300
}
292
301
302
+ static inject < T > ( token : ProviderToken < T > , notFoundValue : undefined , options : InjectOptions & {
303
+ optional ?: false
304
+ } ) : T ;
305
+ static inject < T > ( token : ProviderToken < T > , notFoundValue : null | undefined , options : InjectOptions ) :
306
+ T | null ;
307
+ static inject < T > ( token : ProviderToken < T > , notFoundValue ?: T , options ?: InjectOptions ) : T ;
308
+ /** @deprecated use object-based flags (`InjectOptions`) instead. */
293
309
static inject < T > ( token : ProviderToken < T > , notFoundValue ?: T , flags ?: InjectFlags ) : T ;
310
+ /** @deprecated use object-based flags (`InjectOptions`) instead. */
294
311
static inject < T > ( token : ProviderToken < T > , notFoundValue : null , flags ?: InjectFlags ) : T | null ;
295
- static inject < T > ( token : ProviderToken < T > , notFoundValue ?: T | null , flags ?: InjectFlags ) : T | null {
296
- return TestBedImpl . INSTANCE . inject ( token , notFoundValue , flags ) ;
312
+ static inject < T > (
313
+ token : ProviderToken < T > , notFoundValue ?: T | null , flags ?: InjectFlags | InjectOptions ) : T | null {
314
+ return TestBedImpl . INSTANCE . inject ( token , notFoundValue , convertToBitFlags ( flags ) ) ;
297
315
}
298
316
299
317
/** @deprecated from v9.0.0 use TestBed.inject */
@@ -468,14 +486,22 @@ export class TestBedImpl implements TestBed {
468
486
return this . compiler . compileComponents ( ) ;
469
487
}
470
488
489
+ inject < T > ( token : ProviderToken < T > , notFoundValue : undefined , options : InjectOptions & {
490
+ optional : true
491
+ } ) : T | null ;
492
+ inject < T > ( token : ProviderToken < T > , notFoundValue ?: T , options ?: InjectOptions ) : T ;
493
+ inject < T > ( token : ProviderToken < T > , notFoundValue : null , options ?: InjectOptions ) : T | null ;
494
+ /** @deprecated use object-based flags (`InjectOptions`) instead. */
471
495
inject < T > ( token : ProviderToken < T > , notFoundValue ?: T , flags ?: InjectFlags ) : T ;
496
+ /** @deprecated use object-based flags (`InjectOptions`) instead. */
472
497
inject < T > ( token : ProviderToken < T > , notFoundValue : null , flags ?: InjectFlags ) : T | null ;
473
- inject < T > ( token : ProviderToken < T > , notFoundValue ?: T | null , flags ?: InjectFlags ) : T | null {
498
+ inject < T > ( token : ProviderToken < T > , notFoundValue ?: T | null , flags ?: InjectFlags | InjectOptions ) : T
499
+ | null {
474
500
if ( token as unknown === TestBed ) {
475
501
return this as any ;
476
502
}
477
503
const UNDEFINED = { } as unknown as T ;
478
- const result = this . testModuleRef . injector . get ( token , UNDEFINED , flags ) ;
504
+ const result = this . testModuleRef . injector . get ( token , UNDEFINED , convertToBitFlags ( flags ) ) ;
479
505
return result === UNDEFINED ? this . compiler . injector . get ( token , notFoundValue , flags ) as any :
480
506
result ;
481
507
}
0 commit comments