I have the following code in an angularjs controller:
async updateGrid() {
const paging = angular.copy(this.gridData.getServerCallObj());
try {
const model = await this.service.get(paging);
this._setGridData(model, true);
this._$rootScope.$apply();
} catch (e){
this._notification.error(this._$rootScope.lang.notifications.unexpectedError);
}
}
I am trying to test this code through jasmin. The following test is run:
it('updateGrid() should should call broadcast when fail', async () => {
spyOn(service, 'get').and.callFake(() => {
return Promise.reject();
});
spyOn($rootScope, '$broadcast').and.callThrough();
await ctrl.updateGrid();
expect(service.get).toHaveBeenCalled();
expect($rootScope.$broadcast).toHaveBeenCalled();
});
My issue is that jasmine return a result for the test with the message "spec... has not expectations." before the function completes! I can continue debugging, after jasmin says the test is done, at his end! Of course, after its done, the line expect(service.get).toHaveBeenCalled(); throws and error with the message: "expect' was used when there was no current spec, this could be because an asynchronous test timed out".
Does anyone knows what am I doing wrong here?