I am having trouble asserting that my filter has been called after a promise has been returned.
This code is called from a controller which then pulls the data to filter from a http GET service:
getPermissions(){
return this.DataService.getPermissionsLOV().then((data) => {
return this.$filter('chunkCollection')(data, 3);
});
}
My test case looks like so:
it('should get the permissions', () => {
spyOn(service, 'getPermissions').and.callThrough();
spyOn(DataService, 'getPermissionsLOV').and.callFake(function(){
var defer = this.$q.defer();
defer.resolve(mockData);
return defer.promise;
});
let resp;
service.getPermissions().then((data) => {
resp = data;
});
scope.$digest();
expect(service.getPermissions).toHaveBeenCalled();
expect(DataService.getPermissionsLOV).toHaveBeenCalled();
expect(resp).toEqual(mockData);
});
The assertion expect(resp).toEqual(mockData);
fails as the response is filtered by chunkCollection
but I do not know how to test this call to $filter
?
I have tested the filter itself separately so know that is working and karma tells me it is transforming the data when reporting the failure of the aforementioned assertion.