In my testing, I need to unit test a function that relies on the gridApi, such as this.gridApi.getSelectedRows();
. However, when the unit test encounters this line, it throws an error:
Failed: Cannot read property 'getSelectedRows' of undefined
, because gridApi has not been defined yet.
How can I properly define the gridApi within a unit test? Typically, the gridApi is initialized in the onGridReady function like so:
onGridReady(params) {
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;
this.gridApi.sizeColumnsToFit();
}
Is there a way to trigger the onGridReady
function from a unit test? I'm unsure about what parameters should be passed to it. Alternatively, is there another method to define this.gridApi
instead?