I have a child component that has events in its template such as:
child.html
<a (click)="parent.onClick()"></a>
Normally when I go about testing events in angular2, I would do something like:
child.spec.ts
it('', () => {
let menu = fixture.debugElement.nativeElement.querySelector('a');
menu.click();
fixture.detectChanges();
expect(something)
});
with setup that looks something like:
BeforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ChildComponent]
providers: [ParentComponent]
})
.compileComponents();
But in the case of the calling the parent's method in the child's template, the .click(); never calls the parent's method. If I move the logic into the child component, the test will of course work, however, I was wondering if there was way to test the click event as it is currently setup.
Aucun commentaire:
Enregistrer un commentaire