fix(ivy): ngOnChanges hooks should be inherited from grand-superclasses (#28888)
PR Close #28888
This commit is contained in:
@ -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: ``})
|
||||
|
Reference in New Issue
Block a user