| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  | import {Component as _Component, ComponentFactoryResolver, ElementRef, InjectFlags, Injectable as _Injectable, InjectionToken, InjectorType, Provider, RendererFactory2, ViewContainerRef, ɵNgModuleDef as NgModuleDef, ɵɵdefineInjectable, ɵɵdefineInjector, ɵɵinject} from '../../src/core'; | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  | import {forwardRef} from '../../src/di/forward_ref'; | 
					
						
							| 
									
										
										
										
											2019-02-03 20:43:20 -08:00
										 |  |  | import {createInjector} from '../../src/di/r3_injector'; | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  | import {injectComponentFactoryResolver, ɵɵProvidersFeature, ɵɵadvance, ɵɵdefineComponent, ɵɵdefineDirective, ɵɵdirectiveInject, ɵɵtextInterpolate1} from '../../src/render3/index'; | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  | import {ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵelement, ɵɵelementEnd, ɵɵelementStart, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵtext, ɵɵtextInterpolate} from '../../src/render3/instructions/all'; | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  | import {RenderFlags} from '../../src/render3/interfaces/definition'; | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  | import {NgModuleFactory} from '../../src/render3/ng_module_ref'; | 
					
						
							| 
									
										
										
										
											2019-02-20 14:21:20 -08:00
										 |  |  | import {getInjector} from '../../src/render3/util/discovery_utils'; | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  | import {getRendererFactory2} from './imported_renderer2'; | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  | import {ComponentFixture} from './render_util'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Component: typeof _Component = function(...args: any[]): any { | 
					
						
							|  |  |  |   // In test we use @Component for documentation only so it's safe to mock out the implementation.
 | 
					
						
							|  |  |  |   return () => undefined; | 
					
						
							|  |  |  | } as any; | 
					
						
							|  |  |  | const Injectable: typeof _Injectable = function(...args: any[]): any { | 
					
						
							|  |  |  |   // In test we use @Injectable for documentation only so it's safe to mock out the implementation.
 | 
					
						
							|  |  |  |   return () => undefined; | 
					
						
							|  |  |  | } as any; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('providers', () => { | 
					
						
							|  |  |  |   describe('should support all types of Provider:', () => { | 
					
						
							|  |  |  |     abstract class Greeter { abstract greet: string; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const GREETER = new InjectionToken<Greeter>('greeter'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class GreeterClass implements Greeter { | 
					
						
							|  |  |  |       greet = 'Class'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class GreeterDeps implements Greeter { | 
					
						
							|  |  |  |       constructor(public greet: string) {} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class GreeterBuiltInDeps implements Greeter { | 
					
						
							|  |  |  |       public greet: string; | 
					
						
							|  |  |  |       constructor(private message: string, private elementRef: ElementRef) { | 
					
						
							|  |  |  |         this.greet = this.message + ' from ' + this.elementRef.nativeElement.tagName; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class GreeterProvider { | 
					
						
							|  |  |  |       provide() { return 'Provided'; } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @Injectable() | 
					
						
							|  |  |  |     class GreeterInj implements Greeter { | 
					
						
							|  |  |  |       public greet: string; | 
					
						
							|  |  |  |       constructor(private provider: GreeterProvider) { this.greet = this.provider.provide(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 12:41:30 -07:00
										 |  |  |       static ɵprov = ɵɵdefineInjectable({ | 
					
						
							| 
									
										
										
										
											2019-06-07 10:12:07 -07:00
										 |  |  |         token: GreeterInj, | 
					
						
							|  |  |  |         factory: () => new GreeterInj(ɵɵinject(GreeterProvider as any)), | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('TypeProvider', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [GreeterClass], | 
					
						
							|  |  |  |           componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               () => { expect(ɵɵdirectiveInject(GreeterClass).greet).toEqual('Class'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('ValueProvider', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [{provide: GREETER, useValue: {greet: 'Value'}}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Value'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('ClassProvider', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [{provide: GREETER, useClass: GreeterClass}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Class'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('ExistingProvider', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [GreeterClass, {provide: GREETER, useExisting: GreeterClass}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Class'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('FactoryProvider', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [GreeterClass, {provide: GREETER, useFactory: () => new GreeterClass()}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Class'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const MESSAGE = new InjectionToken<string>('message'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('ClassProvider with deps', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [ | 
					
						
							|  |  |  |             {provide: MESSAGE, useValue: 'Message'}, | 
					
						
							|  |  |  |             {provide: GREETER, useClass: GreeterDeps, deps: [MESSAGE]} | 
					
						
							|  |  |  |           ], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Message'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('ClassProvider with built-in deps', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [ | 
					
						
							|  |  |  |             {provide: MESSAGE, useValue: 'Message'}, | 
					
						
							|  |  |  |             {provide: GREETER, useClass: GreeterBuiltInDeps, deps: [MESSAGE, ElementRef]} | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |           componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Message from PARENT'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('FactoryProvider with deps', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [ | 
					
						
							|  |  |  |             {provide: MESSAGE, useValue: 'Message'}, | 
					
						
							|  |  |  |             {provide: GREETER, useFactory: (msg: string) => new GreeterDeps(msg), deps: [MESSAGE]} | 
					
						
							|  |  |  |           ], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Message'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('FactoryProvider with built-in deps', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [ | 
					
						
							|  |  |  |             {provide: MESSAGE, useValue: 'Message'}, { | 
					
						
							|  |  |  |               provide: GREETER, | 
					
						
							|  |  |  |               useFactory: (msg: string, elementRef: ElementRef) => | 
					
						
							|  |  |  |                               new GreeterBuiltInDeps(msg, elementRef), | 
					
						
							|  |  |  |               deps: [MESSAGE, ElementRef] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |           componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Message from PARENT'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('ClassProvider with injectable', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [GreeterProvider, {provide: GREETER, useClass: GreeterInj}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: | 
					
						
							|  |  |  |               () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Provided'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('forwardRef', () => { | 
					
						
							|  |  |  |       it('forwardRef resolves later', (done) => { | 
					
						
							|  |  |  |         setTimeout(() => { | 
					
						
							|  |  |  |           expectProvidersScenario({ | 
					
						
							|  |  |  |             parent: { | 
					
						
							|  |  |  |               providers: [forwardRef(() => ForLater)], | 
					
						
							|  |  |  |               componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                   () => { expect(ɵɵdirectiveInject(ForLater) instanceof ForLater).toBeTruthy(); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |           done(); | 
					
						
							|  |  |  |         }, 0); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class ForLater {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // The following test that forwardRefs are called, so we don't search for an anon fn
 | 
					
						
							|  |  |  |       it('ValueProvider wrapped in forwardRef', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: | 
					
						
							|  |  |  |                 [{provide: GREETER, useValue: forwardRef(() => { return {greet: 'Value'}; })}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             componentAssertion: () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Value'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('ClassProvider wrapped in forwardRef', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: GREETER, useClass: forwardRef(() => GreeterClass)}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             componentAssertion: () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Class'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('ExistingProvider wrapped in forwardRef', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: | 
					
						
							|  |  |  |                 [GreeterClass, {provide: GREETER, useExisting: forwardRef(() => GreeterClass)}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             componentAssertion: () => { expect(ɵɵdirectiveInject(GREETER).greet).toEqual('Class'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 18:52:51 -08:00
										 |  |  |       it('@Inject annotation wrapped in forwardRef', () => { | 
					
						
							|  |  |  |         // @Inject(forwardRef(() => GREETER))
 | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: GREETER, useValue: {greet: 'Value'}}], | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(forwardRef(() => GREETER)).greet).toEqual('Value'); | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:52:51 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* | 
					
						
							|  |  |  |    * All tests below assume this structure: | 
					
						
							|  |  |  |    * ```
 | 
					
						
							|  |  |  |    * <parent> | 
					
						
							|  |  |  |    *   <#VIEW#> | 
					
						
							|  |  |  |    *     <view-child> | 
					
						
							|  |  |  |    *     </view-child> | 
					
						
							|  |  |  |    *   </#VIEW#> | 
					
						
							|  |  |  |    *   <content-child> | 
					
						
							|  |  |  |    *   </content-child> | 
					
						
							|  |  |  |    * </parent> | 
					
						
							|  |  |  |    * ```
 | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('override rules:', () => { | 
					
						
							|  |  |  |     it('directiveProviders should override providers', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [{provide: String, useValue: 'Message 1'}], | 
					
						
							|  |  |  |           directiveProviders: [{provide: String, useValue: 'Message 2'}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('Message 2'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('viewProviders should override providers', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [{provide: String, useValue: 'Message 1'}], | 
					
						
							|  |  |  |           viewProviders: [{provide: String, useValue: 'Message 2'}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('Message 2'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('viewProviders should override directiveProviders', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           directiveProviders: [{provide: String, useValue: 'Message 1'}], | 
					
						
							|  |  |  |           viewProviders: [{provide: String, useValue: 'Message 2'}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('Message 2'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('last declared directive should override other directives', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           directive2Providers: [{provide: String, useValue: 'Message 1'}], | 
					
						
							|  |  |  |           directiveProviders: [{provide: String, useValue: 'Message 2'}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('Message 2'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('last provider should override previous one in component providers', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: | 
					
						
							|  |  |  |               [{provide: String, useValue: 'Message 1'}, {provide: String, useValue: 'Message 2'}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('Message 2'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('last provider should override previous one in component view providers', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           viewProviders: | 
					
						
							|  |  |  |               [{provide: String, useValue: 'Message 1'}, {provide: String, useValue: 'Message 2'}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('Message 2'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('last provider should override previous one in directive providers', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           directiveProviders: | 
					
						
							|  |  |  |               [{provide: String, useValue: 'Message 1'}, {provide: String, useValue: 'Message 2'}], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('Message 2'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('single', () => { | 
					
						
							|  |  |  |     class MyModule { | 
					
						
							| 
									
										
										
										
											2019-10-14 15:28:01 -07:00
										 |  |  |       static ɵinj = ɵɵdefineInjector( | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           {factory: () => new MyModule(), providers: [{provide: String, useValue: 'From module'}]}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('without directives', () => { | 
					
						
							|  |  |  |       it('should work without providers nor viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('From module'); }, | 
					
						
							|  |  |  |             directiveAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('From module'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('From module'); }, | 
					
						
							|  |  |  |             directiveAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('From module'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('From module'); }, | 
					
						
							|  |  |  |             directiveAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('From module'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with only providers in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: String, useValue: 'From providers'}], | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From providers'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From providers'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From providers'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From providers'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From providers'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From providers'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with only viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             viewProviders: [{provide: String, useValue: 'From viewProviders'}], | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); }, | 
					
						
							|  |  |  |             directiveAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('From module'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             componentAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('From module'); }, | 
					
						
							|  |  |  |             directiveAssertion: () => { expect(ɵɵdirectiveInject(String)).toEqual('From module'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with both providers and viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: String, useValue: 'From providers'}], | 
					
						
							|  |  |  |             viewProviders: [{provide: String, useValue: 'From viewProviders'}], | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From providers'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From providers'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From providers'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |     describe('with directives (order in ɵcmp.directives matters)', () => { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       it('should work without providers nor viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             directiveProviders: [{provide: String, useValue: 'From directive'}], | 
					
						
							|  |  |  |             directive2Providers: [{provide: String, useValue: 'Never'}], | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with only providers in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: String, useValue: 'From providers'}], | 
					
						
							|  |  |  |             directiveProviders: [{provide: String, useValue: 'From directive'}], | 
					
						
							|  |  |  |             directive2Providers: [{provide: String, useValue: 'Never'}], | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with only viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             viewProviders: [{provide: String, useValue: 'From viewProviders'}], | 
					
						
							|  |  |  |             directiveProviders: [{provide: String, useValue: 'From directive'}], | 
					
						
							|  |  |  |             directive2Providers: [{provide: String, useValue: 'Never'}], | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with both providers and viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: String, useValue: 'From providers'}], | 
					
						
							|  |  |  |             viewProviders: [{provide: String, useValue: 'From viewProviders'}], | 
					
						
							|  |  |  |             directiveProviders: [{provide: String, useValue: 'From directive'}], | 
					
						
							|  |  |  |             directive2Providers: [{provide: String, useValue: 'Never'}], | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From viewProviders'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); }, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual('From directive'); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('multi', () => { | 
					
						
							|  |  |  |     class MyModule { | 
					
						
							| 
									
										
										
										
											2019-10-14 15:28:01 -07:00
										 |  |  |       static ɵinj = ɵɵdefineInjector({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         factory: () => new MyModule(), | 
					
						
							|  |  |  |         providers: [{provide: String, useValue: 'From module', multi: true}] | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('without directives', () => { | 
					
						
							|  |  |  |       it('should work without providers nor viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From module']); }, | 
					
						
							|  |  |  |             directiveAssertion: | 
					
						
							|  |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From module']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From module']); }, | 
					
						
							|  |  |  |             directiveAssertion: | 
					
						
							|  |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From module']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From module']); }, | 
					
						
							|  |  |  |             directiveAssertion: | 
					
						
							|  |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From module']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with only providers in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: String, useValue: 'From providers', multi: true}], | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From providers']); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From providers']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From providers']); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From providers']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From providers']); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From providers']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with only viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             viewProviders: [{provide: String, useValue: 'From viewProviders', multi: true}], | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From viewProviders']); }, | 
					
						
							|  |  |  |             directiveAssertion: | 
					
						
							|  |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From module']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From viewProviders']); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From viewProviders']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From module']); }, | 
					
						
							|  |  |  |             directiveAssertion: | 
					
						
							|  |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From module']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with both providers and viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: String, useValue: 'From providers', multi: true}], | 
					
						
							|  |  |  |             viewProviders: [{provide: String, useValue: 'From viewProviders', multi: true}], | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From providers', 'From viewProviders']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From providers']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From providers', 'From viewProviders']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From providers', 'From viewProviders']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From providers']); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             directiveAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 () => { expect(ɵɵdirectiveInject(String)).toEqual(['From providers']); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |     describe('with directives (order in ɵcmp.directives matters)', () => { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       it('should work without providers nor viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             directiveProviders: [{provide: String, useValue: 'From directive 1', multi: true}], | 
					
						
							|  |  |  |             directive2Providers: [{provide: String, useValue: 'From directive 2', multi: true}], | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From directive 2', 'From directive 1']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From directive 2', 'From directive 1']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From directive 2', 'From directive 1']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From directive 2', 'From directive 1']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From directive 2', 'From directive 1']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From directive 2', 'From directive 1']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with only providers in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: String, useValue: 'From providers', multi: true}], | 
					
						
							|  |  |  |             directiveProviders: [{provide: String, useValue: 'From directive 1', multi: true}], | 
					
						
							|  |  |  |             directive2Providers: [{provide: String, useValue: 'From directive 2', multi: true}], | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with only viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             viewProviders: [{provide: String, useValue: 'From viewProviders', multi: true}], | 
					
						
							|  |  |  |             directiveProviders: [{provide: String, useValue: 'From directive 1', multi: true}], | 
					
						
							|  |  |  |             directive2Providers: [{provide: String, useValue: 'From directive 2', multi: true}], | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From viewProviders', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From directive 2', 'From directive 1']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From viewProviders', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From viewProviders', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From directive 2', 'From directive 1']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual(['From directive 2', 'From directive 1']); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with both providers and viewProviders in component', () => { | 
					
						
							|  |  |  |         expectProvidersScenario({ | 
					
						
							|  |  |  |           parent: { | 
					
						
							|  |  |  |             providers: [{provide: String, useValue: 'From providers', multi: true}], | 
					
						
							|  |  |  |             viewProviders: [{provide: String, useValue: 'From viewProviders', multi: true}], | 
					
						
							|  |  |  |             directiveProviders: [{provide: String, useValue: 'From directive 1', multi: true}], | 
					
						
							|  |  |  |             directive2Providers: [{provide: String, useValue: 'From directive 2', multi: true}], | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From viewProviders', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           viewChild: { | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From viewProviders', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From viewProviders', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           contentChild: { | 
					
						
							|  |  |  |             componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directiveAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               expect(ɵɵdirectiveInject(String)).toEqual([ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 'From providers', 'From directive 2', 'From directive 1' | 
					
						
							|  |  |  |               ]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           ngModule: MyModule | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('tree-shakable injectables', () => { | 
					
						
							|  |  |  |     it('should work with root', () => { | 
					
						
							|  |  |  |       @Injectable({providedIn: 'root'}) | 
					
						
							|  |  |  |       class FooForRoot { | 
					
						
							| 
									
										
										
										
											2019-10-15 12:41:30 -07:00
										 |  |  |         static ɵprov = ɵɵdefineInjectable({ | 
					
						
							| 
									
										
										
										
											2019-06-07 10:12:07 -07:00
										 |  |  |           token: FooForRoot, | 
					
						
							|  |  |  |           factory: () => new FooForRoot(), | 
					
						
							|  |  |  |           providedIn: 'root', | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               () => { expect(ɵɵdirectiveInject(FooForRoot) instanceof FooForRoot).toBeTruthy(); } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should work with a module', () => { | 
					
						
							|  |  |  |       class MyModule { | 
					
						
							| 
									
										
										
										
											2019-10-14 15:28:01 -07:00
										 |  |  |         static ɵinj = ɵɵdefineInjector({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           factory: () => new MyModule(), | 
					
						
							|  |  |  |           providers: [{provide: String, useValue: 'From module'}] | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @Injectable({providedIn: MyModule}) | 
					
						
							|  |  |  |       class FooForModule { | 
					
						
							| 
									
										
										
										
											2019-10-15 12:41:30 -07:00
										 |  |  |         static ɵprov = ɵɵdefineInjectable({ | 
					
						
							| 
									
										
										
										
											2019-06-07 10:12:07 -07:00
										 |  |  |           token: FooForModule, | 
					
						
							|  |  |  |           factory: () => new FooForModule(), | 
					
						
							|  |  |  |           providedIn: MyModule, | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           componentAssertion: () => { | 
					
						
							|  |  |  |             expect(ɵɵdirectiveInject(FooForModule) instanceof FooForModule).toBeTruthy(); | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         }, | 
					
						
							|  |  |  |         ngModule: MyModule | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('- embedded views', () => { | 
					
						
							|  |  |  |     it('should have access to viewProviders of the host component', () => { | 
					
						
							|  |  |  |       @Component({ | 
					
						
							|  |  |  |         template: '{{s}}{{n}}', | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       class Repeated { | 
					
						
							|  |  |  |         constructor(private s: String, private n: Number) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |         static ɵfac = | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |             () => { return new Repeated(ɵɵdirectiveInject(String), ɵɵdirectiveInject(Number)); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           type: Repeated, | 
					
						
							|  |  |  |           selectors: [['repeated']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           decls: 2, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           vars: 2, | 
					
						
							|  |  |  |           template: function(fs: RenderFlags, ctx: Repeated) { | 
					
						
							|  |  |  |             if (fs & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵtext(0); | 
					
						
							|  |  |  |               ɵɵtext(1); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (fs & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |               ɵɵtextInterpolate(ctx.s); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |               ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |               ɵɵtextInterpolate(ctx.n); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @Component({ | 
					
						
							|  |  |  |         template: `<div>
 | 
					
						
							|  |  |  |             % for (let i = 0; i < 3; i++) { | 
					
						
							|  |  |  |               <repeated></repeated> | 
					
						
							|  |  |  |             % } | 
					
						
							|  |  |  |           </div>`,
 | 
					
						
							|  |  |  |         providers: [{provide: Number, useValue: 1, multi: true}], | 
					
						
							|  |  |  |         viewProviders: | 
					
						
							|  |  |  |             [{provide: String, useValue: 'foo'}, {provide: Number, useValue: 2, multi: true}], | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       class ComponentWithProviders { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |         static ɵfac = () => new ComponentWithProviders(); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           type: ComponentWithProviders, | 
					
						
							|  |  |  |           selectors: [['component-with-providers']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           decls: 2, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           vars: 0, | 
					
						
							|  |  |  |           template: function(fs: RenderFlags, ctx: ComponentWithProviders) { | 
					
						
							|  |  |  |             if (fs & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵelementStart(0, 'div'); | 
					
						
							|  |  |  |               { ɵɵcontainer(1); } | 
					
						
							|  |  |  |               ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (fs & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵcontainerRefreshStart(1); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |               { | 
					
						
							|  |  |  |                 for (let i = 0; i < 3; i++) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                   let rf1 = ɵɵembeddedViewStart(1, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                   { | 
					
						
							|  |  |  |                     if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                       ɵɵelement(0, 'repeated'); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                   ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           features: [ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵProvidersFeature( | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 [{provide: Number, useValue: 1, multi: true}], | 
					
						
							|  |  |  |                 [{provide: String, useValue: 'foo'}, {provide: Number, useValue: 2, multi: true}]), | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |           directives: [Repeated] | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(ComponentWithProviders); | 
					
						
							|  |  |  |       expect(fixture.html) | 
					
						
							|  |  |  |           .toEqual( | 
					
						
							|  |  |  |               '<div><repeated>foo1,2</repeated><repeated>foo1,2</repeated><repeated>foo1,2</repeated></div>'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should have access to viewProviders of the repeated component', () => { | 
					
						
							|  |  |  |       @Component({ | 
					
						
							|  |  |  |         template: '{{s}}{{n}}', | 
					
						
							|  |  |  |         providers: [{provide: Number, useValue: 1, multi: true}], | 
					
						
							|  |  |  |         viewProviders: | 
					
						
							|  |  |  |             [{provide: String, useValue: 'bar'}, {provide: Number, useValue: 2, multi: true}] | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       class Repeated { | 
					
						
							|  |  |  |         constructor(private s: String, private n: Number) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |         static ɵfac = | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |             () => { return new Repeated(ɵɵdirectiveInject(String), ɵɵdirectiveInject(Number)); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           type: Repeated, | 
					
						
							|  |  |  |           selectors: [['repeated']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           decls: 2, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           vars: 2, | 
					
						
							|  |  |  |           template: function(fs: RenderFlags, ctx: Repeated) { | 
					
						
							|  |  |  |             if (fs & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵtext(0); | 
					
						
							|  |  |  |               ɵɵtext(1); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (fs & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |               ɵɵtextInterpolate(ctx.s); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |               ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |               ɵɵtextInterpolate(ctx.n); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           features: [ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵProvidersFeature( | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 [{provide: Number, useValue: 1, multi: true}], | 
					
						
							|  |  |  |                 [{provide: String, useValue: 'bar'}, {provide: Number, useValue: 2, multi: true}]), | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @Component({ | 
					
						
							|  |  |  |         template: `<div>
 | 
					
						
							|  |  |  |             % for (let i = 0; i < 3; i++) { | 
					
						
							|  |  |  |               <repeated></repeated> | 
					
						
							|  |  |  |             % } | 
					
						
							|  |  |  |           </div>`,
 | 
					
						
							|  |  |  |         viewProviders: [{provide: toString, useValue: 'foo'}], | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       class ComponentWithProviders { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |         static ɵfac = () => new ComponentWithProviders(); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           type: ComponentWithProviders, | 
					
						
							|  |  |  |           selectors: [['component-with-providers']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           decls: 2, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           vars: 0, | 
					
						
							|  |  |  |           template: function(fs: RenderFlags, ctx: ComponentWithProviders) { | 
					
						
							|  |  |  |             if (fs & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵelementStart(0, 'div'); | 
					
						
							|  |  |  |               { ɵɵcontainer(1); } | 
					
						
							|  |  |  |               ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (fs & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵcontainerRefreshStart(1); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |               { | 
					
						
							|  |  |  |                 for (let i = 0; i < 3; i++) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                   let rf1 = ɵɵembeddedViewStart(1, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                   { | 
					
						
							|  |  |  |                     if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                       ɵɵelement(0, 'repeated'); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                   ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           features: [ɵɵProvidersFeature([], [{provide: String, useValue: 'foo'}])], | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           directives: [Repeated] | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(ComponentWithProviders); | 
					
						
							|  |  |  |       expect(fixture.html) | 
					
						
							|  |  |  |           .toEqual( | 
					
						
							|  |  |  |               '<div><repeated>bar1,2</repeated><repeated>bar1,2</repeated><repeated>bar1,2</repeated></div>'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |   describe('- dynamic components dependency resolution', () => { | 
					
						
							|  |  |  |     let hostComponent: HostComponent|null = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @Component({ | 
					
						
							|  |  |  |       template: `{{s}}`, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     class EmbeddedComponent { | 
					
						
							|  |  |  |       constructor(private s: String) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |       static ɵfac = () => new EmbeddedComponent(ɵɵdirectiveInject(String)); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |         type: EmbeddedComponent, | 
					
						
							|  |  |  |         selectors: [['embedded-cmp']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |         decls: 1, | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |         vars: 1, | 
					
						
							|  |  |  |         template: (rf: RenderFlags, cmp: EmbeddedComponent) => { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵtext(0); | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |           if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-31 14:41:07 -07:00
										 |  |  |             ɵɵtextInterpolate1('', cmp.s, ''); | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @Component({template: `foo`, providers: [{provide: String, useValue: 'From host component'}]}) | 
					
						
							|  |  |  |     class HostComponent { | 
					
						
							|  |  |  |       constructor(public vcref: ViewContainerRef, public cfr: ComponentFactoryResolver) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |       static ɵfac = () => hostComponent = new HostComponent( | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |           ɵɵdirectiveInject(ViewContainerRef as any), injectComponentFactoryResolver()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |           static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |             type: HostComponent, | 
					
						
							|  |  |  |             selectors: [['host-cmp']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             decls: 1, | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |             vars: 0, | 
					
						
							|  |  |  |             template: (rf: RenderFlags, cmp: HostComponent) => { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 ɵɵtext(0, 'foo'); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             features: [ | 
					
						
							|  |  |  |               ɵɵProvidersFeature([{provide: String, useValue: 'From host component'}]), | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |           }); | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @Component({ | 
					
						
							|  |  |  |       template: `<host-cmp></host-cmp>`, | 
					
						
							|  |  |  |       providers: [{provide: String, useValue: 'From app component'}] | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     class AppComponent { | 
					
						
							|  |  |  |       constructor() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |       static ɵfac = () => new AppComponent(); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |         type: AppComponent, | 
					
						
							|  |  |  |         selectors: [['app-cmp']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |         decls: 1, | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |         vars: 0, | 
					
						
							|  |  |  |         template: (rf: RenderFlags, cmp: AppComponent) => { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵelement(0, 'host-cmp'); | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         features: [ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵProvidersFeature([{provide: String, useValue: 'From app component'}]), | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |         ], | 
					
						
							|  |  |  |         directives: [HostComponent] | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not cross the root view boundary, and use the root view injector', () => { | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual('<host-cmp>foo</host-cmp>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       hostComponent !.vcref.createComponent( | 
					
						
							|  |  |  |           hostComponent !.cfr.resolveComponentFactory(EmbeddedComponent), undefined, { | 
					
						
							|  |  |  |             get: (token: any, notFoundValue?: any) => { | 
					
						
							|  |  |  |               return token === String ? 'From custom root view injector' : notFoundValue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html) | 
					
						
							|  |  |  |           .toEqual( | 
					
						
							|  |  |  |               '<host-cmp>foo</host-cmp><embedded-cmp>From custom root view injector</embedded-cmp>'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not cross the root view boundary, and use the module injector if no root view injector', | 
					
						
							|  |  |  |        () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |          expect(fixture.html).toEqual('<host-cmp>foo</host-cmp>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          class MyAppModule { | 
					
						
							| 
									
										
										
										
											2019-10-14 15:28:01 -07:00
										 |  |  |            static ɵinj = ɵɵdefineInjector({ | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |              factory: () => new MyAppModule(), | 
					
						
							|  |  |  |              imports: [], | 
					
						
							|  |  |  |              providers: [ | 
					
						
							|  |  |  |                {provide: RendererFactory2, useValue: getRendererFactory2(document)}, | 
					
						
							|  |  |  |                {provide: String, useValue: 'From module injector'} | 
					
						
							|  |  |  |              ] | 
					
						
							|  |  |  |            }); | 
					
						
							| 
									
										
										
										
											2019-10-14 07:20:26 -07:00
										 |  |  |            static ɵmod: NgModuleDef<any> = { bootstrap: [] } as any; | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |          } | 
					
						
							|  |  |  |          const myAppModuleFactory = new NgModuleFactory(MyAppModule); | 
					
						
							|  |  |  |          const ngModuleRef = myAppModuleFactory.create(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          hostComponent !.vcref.createComponent( | 
					
						
							|  |  |  |              hostComponent !.cfr.resolveComponentFactory(EmbeddedComponent), undefined, | 
					
						
							|  |  |  |              {get: (token: any, notFoundValue?: any) => notFoundValue}, undefined, ngModuleRef); | 
					
						
							|  |  |  |          fixture.update(); | 
					
						
							|  |  |  |          expect(fixture.html) | 
					
						
							|  |  |  |              .toMatch( | 
					
						
							| 
									
										
										
										
											2017-06-24 21:09:38 +02:00
										 |  |  |                  /<host-cmp>foo<\/host-cmp><embedded-cmp _nghost-[a-z]+-c(\d+)="">From module injector<\/embedded-cmp>/); | 
					
						
							| 
									
										
										
										
											2018-11-14 17:04:22 +01:00
										 |  |  |        }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should cross the root view boundary to the parent of the host, thanks to the default root view injector', | 
					
						
							|  |  |  |        () => { | 
					
						
							|  |  |  |          const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |          expect(fixture.html).toEqual('<host-cmp>foo</host-cmp>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          hostComponent !.vcref.createComponent( | 
					
						
							|  |  |  |              hostComponent !.cfr.resolveComponentFactory(EmbeddedComponent)); | 
					
						
							|  |  |  |          fixture.update(); | 
					
						
							|  |  |  |          expect(fixture.html) | 
					
						
							|  |  |  |              .toEqual('<host-cmp>foo</host-cmp><embedded-cmp>From app component</embedded-cmp>'); | 
					
						
							|  |  |  |        }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |   describe('deps boundary:', () => { | 
					
						
							|  |  |  |     it('the deps of a token declared in providers should not be resolved with tokens from viewProviders', | 
					
						
							|  |  |  |        () => { | 
					
						
							|  |  |  |          @Injectable() | 
					
						
							|  |  |  |          class MyService { | 
					
						
							|  |  |  |            constructor(public value: String) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 12:41:30 -07:00
										 |  |  |            static ɵprov = ɵɵdefineInjectable({ | 
					
						
							| 
									
										
										
										
											2019-06-07 10:12:07 -07:00
										 |  |  |              token: MyService, | 
					
						
							|  |  |  |              factory: () => new MyService(ɵɵinject(String)), | 
					
						
							|  |  |  |            }); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |          } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          expectProvidersScenario({ | 
					
						
							|  |  |  |            parent: { | 
					
						
							|  |  |  |              providers: [MyService, {provide: String, useValue: 'providers'}], | 
					
						
							|  |  |  |              viewProviders: [{provide: String, useValue: 'viewProviders'}], | 
					
						
							|  |  |  |              componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                expect(ɵɵdirectiveInject(String)).toEqual('viewProviders'); | 
					
						
							|  |  |  |                expect(ɵɵdirectiveInject(MyService).value).toEqual('providers'); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |              } | 
					
						
							|  |  |  |            } | 
					
						
							|  |  |  |          }); | 
					
						
							|  |  |  |        }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should make sure that parent service does not see overrides in child directives', () => { | 
					
						
							|  |  |  |       class Greeter { | 
					
						
							| 
									
										
										
										
											2019-10-15 12:41:30 -07:00
										 |  |  |         static ɵprov = ɵɵdefineInjectable({ | 
					
						
							| 
									
										
										
										
											2019-06-07 10:12:07 -07:00
										 |  |  |           token: Greeter, | 
					
						
							|  |  |  |           factory: () => new Greeter(ɵɵinject(String)), | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         constructor(public greeting: String) {} | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           providers: [Greeter, {provide: String, useValue: 'parent'}], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         viewChild: { | 
					
						
							|  |  |  |           providers: [{provide: String, useValue: 'view'}], | 
					
						
							|  |  |  |           componentAssertion: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               () => { expect(ɵɵdirectiveInject(Greeter).greeting).toEqual('parent'); }, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('injection flags', () => { | 
					
						
							|  |  |  |     class MyModule { | 
					
						
							| 
									
										
										
										
											2019-10-14 15:28:01 -07:00
										 |  |  |       static ɵinj = ɵɵdefineInjector( | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           {factory: () => new MyModule(), providers: [{provide: String, useValue: 'Module'}]}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     it('should not fall through to ModuleInjector if flags limit the scope', () => { | 
					
						
							|  |  |  |       expectProvidersScenario({ | 
					
						
							|  |  |  |         ngModule: MyModule, | 
					
						
							|  |  |  |         parent: { | 
					
						
							|  |  |  |           componentAssertion: () => { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             expect(ɵɵdirectiveInject(String)).toEqual('Module'); | 
					
						
							|  |  |  |             expect(ɵɵdirectiveInject(String, InjectFlags.Optional | InjectFlags.Self)).toBeNull(); | 
					
						
							|  |  |  |             expect(ɵɵdirectiveInject(String, InjectFlags.Optional | InjectFlags.Host)).toBeNull(); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |   describe('from a node without injector', () => { | 
					
						
							|  |  |  |     abstract class Some { abstract location: String; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class SomeInj implements Some { | 
					
						
							|  |  |  |       constructor(public location: String) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 12:41:30 -07:00
										 |  |  |       static ɵprov = ɵɵdefineInjectable({ | 
					
						
							| 
									
										
										
										
											2019-06-07 10:12:07 -07:00
										 |  |  |         token: SomeInj, | 
					
						
							|  |  |  |         factory: () => new SomeInj(ɵɵinject(String)), | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 15:38:40 +01:00
										 |  |  |     @Component({ | 
					
						
							|  |  |  |       template: `<p></p>`, | 
					
						
							|  |  |  |       providers: [{provide: String, useValue: 'From my component'}], | 
					
						
							|  |  |  |       viewProviders: [{provide: Number, useValue: 123}] | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |     class MyComponent { | 
					
						
							|  |  |  |       constructor() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |       static ɵfac = () => new MyComponent(); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |         type: MyComponent, | 
					
						
							|  |  |  |         selectors: [['my-cmp']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |         decls: 1, | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |         vars: 0, | 
					
						
							|  |  |  |         template: (rf: RenderFlags, cmp: MyComponent) => { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵelement(0, 'p'); | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         features: [ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵProvidersFeature( | 
					
						
							| 
									
										
										
										
											2019-01-04 15:38:40 +01:00
										 |  |  |               [{provide: String, useValue: 'From my component'}], | 
					
						
							|  |  |  |               [{provide: Number, useValue: 123}]), | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |         ], | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @Component({ | 
					
						
							|  |  |  |       template: `<my-cmp></my-cmp>`, | 
					
						
							|  |  |  |       providers: | 
					
						
							|  |  |  |           [{provide: String, useValue: 'From app component'}, {provide: Some, useClass: SomeInj}] | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     class AppComponent { | 
					
						
							|  |  |  |       constructor() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |       static ɵfac = () => new AppComponent(); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |         type: AppComponent, | 
					
						
							|  |  |  |         selectors: [['app-cmp']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |         decls: 1, | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |         vars: 0, | 
					
						
							|  |  |  |         template: (rf: RenderFlags, cmp: AppComponent) => { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵelement(0, 'my-cmp'); | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         features: [ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵProvidersFeature([ | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |             {provide: String, useValue: 'From app component'}, {provide: Some, useClass: SomeInj} | 
					
						
							|  |  |  |           ]), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         directives: [MyComponent] | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 15:38:40 +01:00
										 |  |  |     it('should work from within the template', () => { | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual('<my-cmp><p></p></my-cmp>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const p = fixture.hostElement.querySelector('p'); | 
					
						
							|  |  |  |       const injector = getInjector(p as any); | 
					
						
							| 
									
										
										
										
											2019-01-04 15:38:40 +01:00
										 |  |  |       expect(injector.get(Number)).toEqual(123); | 
					
						
							|  |  |  |       expect(injector.get(String)).toEqual('From my component'); | 
					
						
							|  |  |  |       expect(injector.get(Some).location).toEqual('From app component'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should work from the host of the component', () => { | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual('<my-cmp><p></p></my-cmp>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const myCmp = fixture.hostElement.querySelector('my-cmp'); | 
					
						
							|  |  |  |       const injector = getInjector(myCmp as any); | 
					
						
							|  |  |  |       expect(injector.get(Number)).toEqual(123); | 
					
						
							| 
									
										
										
										
											2018-11-16 15:25:38 +01:00
										 |  |  |       expect(injector.get(String)).toEqual('From my component'); | 
					
						
							|  |  |  |       expect(injector.get(Some).location).toEqual('From app component'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('lifecycles', () => { | 
					
						
							|  |  |  |     it('should execute ngOnDestroy hooks on providers (and only this one)', () => { | 
					
						
							|  |  |  |       const logs: string[] = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @Injectable() | 
					
						
							|  |  |  |       class InjectableWithLifeCycleHooks { | 
					
						
							|  |  |  |         ngOnChanges() { logs.push('Injectable OnChanges'); } | 
					
						
							|  |  |  |         ngOnInit() { logs.push('Injectable OnInit'); } | 
					
						
							|  |  |  |         ngDoCheck() { logs.push('Injectable DoCheck'); } | 
					
						
							|  |  |  |         ngAfterContentInit() { logs.push('Injectable AfterContentInit'); } | 
					
						
							|  |  |  |         ngAfterContentChecked() { logs.push('Injectable AfterContentChecked'); } | 
					
						
							|  |  |  |         ngAfterViewInit() { logs.push('Injectable AfterViewInit'); } | 
					
						
							|  |  |  |         ngAfterViewChecked() { logs.push('Injectable gAfterViewChecked'); } | 
					
						
							|  |  |  |         ngOnDestroy() { logs.push('Injectable OnDestroy'); } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @Component({template: `<span></span>`, providers: [InjectableWithLifeCycleHooks]}) | 
					
						
							|  |  |  |       class MyComponent { | 
					
						
							|  |  |  |         constructor(foo: InjectableWithLifeCycleHooks) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |         static ɵfac = | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |             () => { return new MyComponent(ɵɵdirectiveInject(InjectableWithLifeCycleHooks)); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |           type: MyComponent, | 
					
						
							|  |  |  |           selectors: [['my-comp']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           decls: 1, | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |           vars: 0, | 
					
						
							|  |  |  |           template: (rf: RenderFlags, ctx: MyComponent) => { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵelement(0, 'span'); | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           features: [ɵɵProvidersFeature([InjectableWithLifeCycleHooks])] | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @Component({ | 
					
						
							|  |  |  |         template: `
 | 
					
						
							|  |  |  |         <div> | 
					
						
							|  |  |  |         % if (ctx.condition) { | 
					
						
							|  |  |  |           <my-comp></my-comp> | 
					
						
							|  |  |  |         % } | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       class App { | 
					
						
							|  |  |  |         public condition = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |         static ɵfac = () => new App(); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |           type: App, | 
					
						
							|  |  |  |           selectors: [['app-cmp']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           decls: 2, | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |           vars: 0, | 
					
						
							|  |  |  |           template: (rf: RenderFlags, ctx: App) => { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵelementStart(0, 'div'); | 
					
						
							|  |  |  |               { ɵɵcontainer(1); } | 
					
						
							|  |  |  |               ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵcontainerRefreshStart(1); | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |               { | 
					
						
							|  |  |  |                 if (ctx.condition) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                   let rf1 = ɵɵembeddedViewStart(1, 2, 1); | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |                   { | 
					
						
							|  |  |  |                     if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                       ɵɵelement(0, 'my-comp'); | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                   ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           directives: [MyComponent] | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual('<div><my-comp><span></span></my-comp></div>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       fixture.component.condition = false; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual('<div></div>'); | 
					
						
							|  |  |  |       expect(logs).toEqual(['Injectable OnDestroy']); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-01-31 10:38:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-07 17:07:39 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | interface ComponentTest { | 
					
						
							|  |  |  |   providers?: Provider[]; | 
					
						
							|  |  |  |   viewProviders?: Provider[]; | 
					
						
							|  |  |  |   directiveProviders?: Provider[]; | 
					
						
							|  |  |  |   directive2Providers?: Provider[]; | 
					
						
							|  |  |  |   directiveAssertion?: () => void; | 
					
						
							|  |  |  |   componentAssertion?: () => void; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function expectProvidersScenario(defs: { | 
					
						
							|  |  |  |   app?: ComponentTest, | 
					
						
							|  |  |  |   parent?: ComponentTest, | 
					
						
							|  |  |  |   viewChild?: ComponentTest, | 
					
						
							|  |  |  |   contentChild?: ComponentTest, | 
					
						
							|  |  |  |   ngModule?: InjectorType<any>, | 
					
						
							|  |  |  | }): void { | 
					
						
							|  |  |  |   function testComponentInjection<T>(def: ComponentTest | undefined, instance: T): T { | 
					
						
							|  |  |  |     if (def) { | 
					
						
							|  |  |  |       def.componentAssertion && def.componentAssertion(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return instance; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function testDirectiveInjection<T>(def: ComponentTest | undefined, instance: T): T { | 
					
						
							|  |  |  |     if (def) { | 
					
						
							|  |  |  |       def.directiveAssertion && def.directiveAssertion(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return instance; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class ViewChildComponent { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = () => testComponentInjection(defs.viewChild, new ViewChildComponent()); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |     static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       type: ViewChildComponent, | 
					
						
							|  |  |  |       selectors: [['view-child']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |       decls: 1, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       vars: 0, | 
					
						
							|  |  |  |       template: function(fs: RenderFlags, ctx: ViewChildComponent) { | 
					
						
							|  |  |  |         if (fs & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵtext(0, 'view-child'); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       features: defs.viewChild && | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |           [ɵɵProvidersFeature(defs.viewChild.providers || [], defs.viewChild.viewProviders || [])] | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class ViewChildDirective { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = () => testDirectiveInjection(defs.viewChild, new ViewChildDirective()); | 
					
						
							| 
									
										
										
										
											2019-10-11 12:28:12 -07:00
										 |  |  |     static ɵdir = ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       type: ViewChildDirective, | 
					
						
							|  |  |  |       selectors: [['view-child']], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       features: defs.viewChild && [ɵɵProvidersFeature(defs.viewChild.directiveProviders || [])], | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class ContentChildComponent { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |         () => { return testComponentInjection(defs.contentChild, new ContentChildComponent()); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |     static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       type: ContentChildComponent, | 
					
						
							|  |  |  |       selectors: [['content-child']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |       decls: 1, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       vars: 0, | 
					
						
							|  |  |  |       template: function(fs: RenderFlags, ctx: ParentComponent) { | 
					
						
							|  |  |  |         if (fs & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵtext(0, 'content-child'); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       features: defs.contentChild && | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           [ɵɵProvidersFeature( | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |               defs.contentChild.providers || [], defs.contentChild.viewProviders || [])], | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class ContentChildDirective { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |         () => { return testDirectiveInjection(defs.contentChild, new ContentChildDirective()); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 12:28:12 -07:00
										 |  |  |     static ɵdir = ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       type: ContentChildDirective, | 
					
						
							|  |  |  |       selectors: [['content-child']], | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |       features: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           defs.contentChild && [ɵɵProvidersFeature(defs.contentChild.directiveProviders || [])], | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class ParentComponent { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = () => testComponentInjection(defs.parent, new ParentComponent()); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |     static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       type: ParentComponent, | 
					
						
							|  |  |  |       selectors: [['parent']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |       decls: 1, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       vars: 0, | 
					
						
							|  |  |  |       template: function(fs: RenderFlags, ctx: ParentComponent) { | 
					
						
							|  |  |  |         if (fs & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵelement(0, 'view-child'); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       features: defs.parent && | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           [ɵɵProvidersFeature(defs.parent.providers || [], defs.parent.viewProviders || [])], | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       directives: [ViewChildComponent, ViewChildDirective] | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class ParentDirective { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = () => testDirectiveInjection(defs.parent, new ParentDirective()); | 
					
						
							| 
									
										
										
										
											2019-10-11 12:28:12 -07:00
										 |  |  |     static ɵdir = ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       type: ParentDirective, | 
					
						
							|  |  |  |       selectors: [['parent']], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       features: defs.parent && [ɵɵProvidersFeature(defs.parent.directiveProviders || [])], | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class ParentDirective2 { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = () => testDirectiveInjection(defs.parent, new ParentDirective2()); | 
					
						
							| 
									
										
										
										
											2019-10-11 12:28:12 -07:00
										 |  |  |     static ɵdir = ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       type: ParentDirective2, | 
					
						
							|  |  |  |       selectors: [['parent']], | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       features: defs.parent && [ɵɵProvidersFeature(defs.parent.directive2Providers || [])], | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class App { | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = () => testComponentInjection(defs.app, new App()); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |     static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       type: App, | 
					
						
							|  |  |  |       selectors: [['app']], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |       decls: 2, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       vars: 0, | 
					
						
							|  |  |  |       template: function(fs: RenderFlags, ctx: App) { | 
					
						
							|  |  |  |         if (fs & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵelementStart(0, 'parent'); | 
					
						
							|  |  |  |           ɵɵelement(1, 'content-child'); | 
					
						
							|  |  |  |           ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       features: | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           defs.app && [ɵɵProvidersFeature(defs.app.providers || [], defs.app.viewProviders || [])], | 
					
						
							| 
									
										
										
										
											2018-11-12 18:40:08 -08:00
										 |  |  |       directives: [ | 
					
						
							|  |  |  |         ParentComponent, ParentDirective2, ParentDirective, ContentChildComponent, | 
					
						
							|  |  |  |         ContentChildDirective | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const fixture = new ComponentFixture( | 
					
						
							|  |  |  |       App, {injector: defs.ngModule ? createInjector(defs.ngModule) : undefined}); | 
					
						
							|  |  |  |   expect(fixture.html).toEqual('<parent><view-child>view-child</view-child></parent>'); | 
					
						
							|  |  |  | } |