以下是我服务的代码
@Injectable()
export class ToolbarService {
/// this event will be subscribed to Detail Component to receive the selected toggle value
public onToggleValueChangeEvent: EventEmitter<ToggleValueType> = new EventEmitter<ToggleValueType>();
/// This Method will be call from Toolbar Component to raise onToggleValueChangeEvent
raiseToggleFilterValueChange(toggleValue: ToggleValueType) {
this.onToggleValueChangeEvent.emit(toggleValue);
}
}
以下是我的明细组件的代码
@Component({
selector: 'app--detail',
templateUrl: './-detail.component.html',
})
export class DetailComponent implements OnInit, OnDestroy {
constructor(private toolbarService: ToolbarService) {
this.toolbarService.onToggleValueChangeEvent.subscribe(x => this.onToggleChange(x));
}
private onToggleChange(event: ToggleValueType) {
console.log(event);
///Filter with Toggle Value
}
}
我想为Detail组件编写单元测试。我想要检查onToggleChange应该使用不同的切换值进行调用。但onToggleChange是私有的,所以我必须使用mock onToggleValueChangeEvent来发出。
请帮助:(