| 
									
										
										
										
											2018-04-12 12:30:21 -07: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  | import {MockDirectory, setup} from '@angular/compiler/test/aot/test_util'; | 
					
						
							| 
									
										
										
										
											2018-04-12 12:30:21 -07:00
										 |  |  | import {compile, expectEmit} from './mock_compile'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('compiler compliance: dependency injection', () => { | 
					
						
							|  |  |  |   const angularFiles = setup({ | 
					
						
							| 
									
										
										
										
											2018-08-01 09:52:34 +02:00
										 |  |  |     compileAngular: false, | 
					
						
							|  |  |  |     compileFakeCore: true, | 
					
						
							| 
									
										
										
										
											2018-04-12 12:30:21 -07:00
										 |  |  |     compileAnimations: false, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should create factory methods', () => { | 
					
						
							|  |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule, Injectable, Attribute, Host, SkipSelf, Self, Optional} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Injectable() | 
					
						
							|  |  |  |               export class MyService {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`\`
 | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent { | 
					
						
							|  |  |  |                 constructor( | 
					
						
							|  |  |  |                   @Attribute('name') name:string, | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |                   s1: MyService, | 
					
						
							| 
									
										
										
										
											2018-04-12 12:30:21 -07:00
										 |  |  |                   @Host() s2: MyService, | 
					
						
							|  |  |  |                   @Self() s4: MyService, | 
					
						
							|  |  |  |                   @SkipSelf() s3: MyService, | 
					
						
							|  |  |  |                   @Optional() s5: MyService, | 
					
						
							|  |  |  |                   @Self() @Optional() s6: MyService, | 
					
						
							|  |  |  |                 ) {} | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 09:52:34 +02:00
										 |  |  |               @NgModule({declarations: [MyComponent], providers: [MyService]}) | 
					
						
							| 
									
										
										
										
											2018-04-12 12:30:21 -07:00
										 |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const factory = `
 | 
					
						
							| 
									
										
										
										
											2018-07-16 16:36:31 -07:00
										 |  |  |       factory: function MyComponent_Factory(t) { | 
					
						
							|  |  |  |         return new (t || MyComponent)( | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $r3$.ɵɵinjectAttribute('name'), | 
					
						
							|  |  |  |           $r3$.ɵɵdirectiveInject(MyService), | 
					
						
							|  |  |  |           $r3$.ɵɵdirectiveInject(MyService, 1), | 
					
						
							|  |  |  |           $r3$.ɵɵdirectiveInject(MyService, 2), | 
					
						
							|  |  |  |           $r3$.ɵɵdirectiveInject(MyService, 4), | 
					
						
							|  |  |  |           $r3$.ɵɵdirectiveInject(MyService, 8), | 
					
						
							|  |  |  |           $r3$.ɵɵdirectiveInject(MyService, 10) | 
					
						
							| 
									
										
										
										
											2018-04-12 12:30:21 -07:00
										 |  |  |         ); | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, factory, 'Incorrect factory'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |