fix(ivy): ngOnChanges should be inherited from super class (#28563)

PR Close #28563
This commit is contained in:
Marc Laval
2019-02-06 15:03:42 +01:00
committed by Miško Hevery
parent fe8301c462
commit 94b8aaeba8
6 changed files with 105 additions and 89 deletions

View File

@ -0,0 +1,60 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* 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
*/
import {Component, Directive, Input, OnChanges, Type} from '@angular/core';
import {TestBed} from '@angular/core/testing';
describe('ngOnChanges', () => {
it('should be inherited when super is a directive', () => {
const log: string[] = [];
@Directive({selector: '[superDir]'})
class SuperDirective implements OnChanges {
@Input() someInput = '';
ngOnChanges() { log.push('on changes!'); }
}
@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', () => {
const log: string[] = [];
class SuperClass {
ngOnChanges() { log.push('on changes!'); }
}
@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: ``})
class AppComp {
}