fix(ivy): use default selector for Components if selector is empty (#29239)

Prior to this change default selector for Components was not applied in case selector is missing or defined as an empty string. This update aligns this behavior between Ivy and VE: now default selector is used for Components when it's needed. Directives with empty selector are not allowed and trigger a compile-time error in both Ivy and VE.

PR Close #29239
This commit is contained in:
Andrew Kushnir
2019-03-11 17:58:37 -07:00
committed by Kara Erickson
parent 9d4b7d7d41
commit fe76494759
3 changed files with 85 additions and 1 deletions

View File

@ -1426,6 +1426,20 @@ function declareTests(config?: {useJit: boolean}) {
.toThrowError(`Directive ${stringify(SomeDirective)} has no selector, please add it!`);
});
it('should throw when using directives with empty string selector', () => {
@Directive({selector: ''})
class SomeDirective {
}
@Component({selector: 'comp', template: ''})
class SomeComponent {
}
TestBed.configureTestingModule({declarations: [MyComp, SomeDirective, SomeComponent]});
expect(() => TestBed.createComponent(MyComp))
.toThrowError(`Directive ${stringify(SomeDirective)} has no selector, please add it!`);
});
it('should use a default element name for components without selectors', () => {
let noSelectorComponentFactory: ComponentFactory<SomeComponent> = undefined !;