fix(ivy): ngOnChanges hooks should be inherited from grand-superclasses (#28888)

PR Close #28888
This commit is contained in:
Marc Laval
2019-02-21 16:42:29 +01:00
committed by Ben Lesh
parent 7f3e3a8c45
commit 9dac04ff50
4 changed files with 132 additions and 62 deletions

View File

@ -127,8 +127,6 @@ export function InheritDefinitionFeature(definition: DirectiveDef<any>| Componen
}
}
}
break;
} else {
// Even if we don't have a definition, check the type for the hooks and use those if need be
const superPrototype = superType.prototype;

View File

@ -53,6 +53,106 @@ describe('ngOnChanges', () => {
expect(log).toEqual(['on changes!']);
});
it('should be inherited when super is a directive and grand-super is a directive', () => {
const log: string[] = [];
@Directive({selector: '[grandSuperDir]'})
class GrandSuperDirective implements OnChanges {
@Input() someInput = '';
ngOnChanges() { log.push('on changes!'); }
}
@Directive({selector: '[superDir]'})
class SuperDirective extends GrandSuperDirective {
}
@Directive({selector: '[subDir]'})
class SubDirective extends SuperDirective {
}
TestBed.configureTestingModule({declarations: [AppComp, SubDirective]});
TestBed.overrideComponent(
AppComp, {set: new Component({template: '<div subDir [someInput]="1"></div>'})});
const fixture = TestBed.createComponent(AppComp);
fixture.detectChanges();
expect(log).toEqual(['on changes!']);
});
it('should be inherited when super is a directive and grand-super is a simple class', () => {
const log: string[] = [];
class GrandSuperClass {
ngOnChanges() { log.push('on changes!'); }
}
@Directive({selector: '[superDir]'})
class SuperDirective extends GrandSuperClass {
@Input() someInput = '';
}
@Directive({selector: '[subDir]'})
class SubDirective extends SuperDirective {
}
TestBed.configureTestingModule({declarations: [AppComp, SubDirective]});
TestBed.overrideComponent(
AppComp, {set: new Component({template: '<div subDir [someInput]="1"></div>'})});
const fixture = TestBed.createComponent(AppComp);
fixture.detectChanges();
expect(log).toEqual(['on changes!']);
});
it('should be inherited when super is a simple class and grand-super is a directive', () => {
const log: string[] = [];
@Directive({selector: '[grandSuperDir]'})
class GrandSuperDirective implements OnChanges {
@Input() someInput = '';
ngOnChanges() { log.push('on changes!'); }
}
class SuperClass extends GrandSuperDirective {}
@Directive({selector: '[subDir]'})
class SubDirective extends SuperClass {
}
TestBed.configureTestingModule({declarations: [AppComp, SubDirective]});
TestBed.overrideComponent(
AppComp, {set: new Component({template: '<div subDir [someInput]="1"></div>'})});
const fixture = TestBed.createComponent(AppComp);
fixture.detectChanges();
expect(log).toEqual(['on changes!']);
});
it('should be inherited when super is a simple class and grand-super is a simple class', () => {
const log: string[] = [];
class GrandSuperClass {
ngOnChanges() { log.push('on changes!'); }
}
class SuperClass extends GrandSuperClass {}
@Directive({selector: '[subDir]'})
class SubDirective extends SuperClass {
@Input() someInput = '';
}
TestBed.configureTestingModule({declarations: [AppComp, SubDirective]});
TestBed.overrideComponent(
AppComp, {set: new Component({template: '<div subDir [someInput]="1"></div>'})});
const fixture = TestBed.createComponent(AppComp);
fixture.detectChanges();
expect(log).toEqual(['on changes!']);
});
});
@Component({selector: 'app-comp', template: ``})