I have a plunkr, and been trying to figure out how to test the EventEmitter after having tried following some of the suggestions on the web without success. I would like to know how to test it by triggering a click of the button...so more of a component test. The code is within the voter.component.ts and voter.componet.spec.ts file. Any help with this would be greatly appreciated.
it('should emit on up/down vote click', fakeAsync((): void => {
let fixture: ComponentFixture = TestBed.createComponent(VoterComponent);
let instance: VoterComponent = fixture.componentInstance;
spyOn(instance.onVote, 'emit');
let button = findElement(fixture, 'button:first-child');
button.click();
fixture.detectChanges();
tick();
expect(instance.onVote.emit).toHaveBeenCalled(1);
}));
Aucun commentaire:
Enregistrer un commentaire