Unit testing – onGridReady – Ag-grid event in Angular
I am having a function like below in my component file like below
onGridReady(params) {
this.gridApi = params.api;
this.columnApi = params.columnApi;
this.gridApi.setDomLayout('autoHeight');
this.gridApi.sizeColumnsToFit();
params.api.setRowData(this.deviceConfigurations);
}
For the above function i am writing the spec like the below one
describe('#onGridReady()', () => {
const params = {
api: new MockGridApi(),
ColumnApi: new MockColumnApi(),
};
it('call the function', () => {
spyOn(component, 'onGridReady').and.callThrough();
component.onGridReady(params);
expect(component.onGridReady).toHaveBeenCalled();
});
});
The spec passes as well as the coverage is done for the above function. But i would like to know whether is it the correct way or writing the spec or do i need to write more specs like to sizeColumnsToFit()
has been called etc.,
Could anyone can give your view about it.
Source: Angular Questions
Any update on this?