我正在为输出事件发射器编写简单的单元测试用例:
describe('ConfirmDeclineComponent',()=> {
function findElement(fixture: ComponentFixture<ConfirmDeclineComponent>, selector: string): any {
return fixture.debugElement.query(By.css(selector)).nativeElement;
}it('should emit on click back button', fakeAsync((): void => {
let fixture = TestBed.createComponent(ConfirmDeclineComponent);
let instance: ConfirmDeclineComponent = fixture.componentInstance;
spyOn(instance.submitConfirmInfoParent, 'emit');
let button = findElement(fixture, '.back-btn')
button.dispatchEvent(new Event('click'));
fixture.detectChanges();
tick();
expect(comp.submitConfirmInfoParent.emit).toHaveBeenCalled();
}));});
@Component({
selector: "decline",
templateUrl: "<button md-raised-button class="back-btn" color="accent" (click)="navigateToVinValidation()" style="margin-right:25px;padding:0px">
<md-icon class="fa fa-arrow-left"></md-icon>
{{'COMMON.BACK' | translate}}
</button>"})`export class ConfirmDeclineComponent implements OnInit {
@Output() navigateToVinValidationParent = new EventEmitter();
ngOnInit() {}
navigateToVinValidation() {
this.navigateToVinValidationParent.emit();
}}`
我收到以下错误:
**Expected spy emit to have been called**