I am having problems trying to test a viewChild on Angular with Jest.
Here my .ts component:
import { MurQueryViewComponent } from '../../shared/components/mur-query-view/mur-query-view.component';
@ViewChild(MurQueryViewComponent) private consultQuery!: MurQueryViewComponent;
This is the method Im trying to test. The method I can not access is applyTransaction
newVolatility() {
this.dialogSrv
.setDialogAction({
component: VolatilityActionComponent,
data: {
actionType: 'Alta',
},
})
.subscribe((res) => {
if (!res) return;
res.attributes.id = res.id;
this.consultQuery.agGrid.api.applyTransaction({
add: [res.attributes],
});
this.dialogSrv.setAlert({ type: 'success', msg: 'message_new_success' });
});
}
Here my .spec.ts:
This is the test that try to prove that previous methos is been call with same arguments:
it('Method newVolatility', () => {
const sonDebugElement = fixture.debugElement.query(By.directive(MurQueryViewComponent));
const sonComponent: MurQueryViewComponent = sonDebugElement.componentInstance;
component['consultQuery'] = sonComponent;
const SpySetItems= jest.spyOn(component['consultQuery'].agGrid.api, 'applyTransaction');
const SpyDialogAlert= jest.spyOn(component['dialogSrv'], 'setAlert');
component['dialogSrv'].setDialogAction = () => {
return of(mockRow);
}
component.newVolatility();
expect(SpySetItems).toBeCalledWith({add: [mockNewRow]});
expect(SpyDialogAlert).toBeCalledWith({ type: 'success', msg: 'message_new_success' });
});
Here the error on terminal:
Anyone could please let me know how to access a viewChild, witch is a whole component and access to its methos?