| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-16 09:00:03 -07:00
										 |  |  | import {Component, Directive, Injector} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2020-04-08 10:14:18 -07:00
										 |  |  | import {inject, TestBed} from '@angular/core/testing'; | 
					
						
							| 
									
										
										
										
											2017-08-16 09:00:03 -07:00
										 |  |  | import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector'; | 
					
						
							| 
									
										
										
										
											2017-05-18 13:46:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 12:12:46 -08:00
										 |  |  | import {MockDirectiveResolver} from '../testing'; | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:42:55 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-28 06:31:26 -07:00
										 |  |  |   describe('MockDirectiveResolver', () => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     let dirResolver: MockDirectiveResolver; | 
					
						
							| 
									
										
										
										
											2015-03-30 15:45:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 13:51:45 -07:00
										 |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       TestBed.configureTestingModule( | 
					
						
							|  |  |  |           {declarations: [SomeDirective, SomeOtherDirective, SomeComponent]}); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 06:31:26 -07:00
										 |  |  |     beforeEach(inject([Injector], (injector: Injector) => { | 
					
						
							| 
									
										
										
										
											2017-08-16 09:00:03 -07:00
										 |  |  |       dirResolver = new MockDirectiveResolver(new JitReflector()); | 
					
						
							| 
									
										
										
										
											2016-07-28 06:31:26 -07:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-03-30 15:45:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 06:45:22 -07:00
										 |  |  |     describe('Directive overriding', () => { | 
					
						
							|  |  |  |       it('should fallback to the default DirectiveResolver when templates are not overridden', | 
					
						
							|  |  |  |          () => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |            const ngModule = dirResolver.resolve(SomeComponent); | 
					
						
							| 
									
										
										
										
											2016-07-28 06:45:22 -07:00
										 |  |  |            expect(ngModule.selector).toEqual('cmp'); | 
					
						
							|  |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |       it('should allow overriding the @Directive', () => { | 
					
						
							| 
									
										
										
										
											2016-09-12 19:14:17 -07:00
										 |  |  |         dirResolver.setDirective(SomeComponent, new Component({selector: 'someOtherSelector'})); | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |         const metadata = dirResolver.resolve(SomeComponent); | 
					
						
							| 
									
										
										
										
											2016-07-28 06:45:22 -07:00
										 |  |  |         expect(metadata.selector).toEqual('someOtherSelector'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-03-30 15:45:03 +02:00
										 |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 13:51:45 -07:00
										 |  |  | @Directive({selector: 'some-directive'}) | 
					
						
							|  |  |  | class SomeDirective { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-06-02 17:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 13:51:45 -07:00
										 |  |  | @Component({selector: 'cmp', template: 'template'}) | 
					
						
							| 
									
										
										
										
											2015-03-30 15:45:03 +02:00
										 |  |  | class SomeComponent { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 13:51:45 -07:00
										 |  |  | @Directive({selector: 'some-other-directive'}) | 
					
						
							|  |  |  | class SomeOtherDirective { | 
					
						
							|  |  |  | } |