如何防止子组件发出的事件名称的意外更改?
@Component({
selector: 'app-update',
template: '<app-reboot-panel (reboot)="doReboot()"></app-reboot-panel>'
})
export class ParentComponent {
doReboot() {
console.log('reboot action started');
}
}
@Component({
selector: 'app-reboot-panel',
template: '<div><button (click)="onReboot()">Reboot</button></div>'
})
export class RebootComponent {
@Output() reboot = new EventEmitter();
onReboot() {
console.log('reboot buton clicked');
this.reboot.emit();
}
}
如果在模板或ts中更改 ParentComponent.doReboot()
的名称,则AoT构建将检测到它并失败 .
如果更改了发出事件的名称 @Output() reboot
,则编译器不会检测到它 .
Angular中是否有任何内置机制来检查 ParentComponent
中是否存在 ParentComponent
中使用的所有事件?如果不是,我如何在父组件中单元测试正确的@Output赋值?我知道我可以单元测试 RebootComponent
,但是可以更改 @Output() reboot
并修复测试,因为它没有触及 ParentComponent
.