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