I have the below function in my angular service "config.service.ts". I have written some unit test cases for the same and I'm unable to cover the error part of the subscribe method.
getConfiguration(params){
return new Promise((resolve, reject) => {
try {
this.httpService.post('getConfig', params).subscribe{
data => {
resolve(data);
},
error => {
reject(error);
}
};
} catch(error) {
reject(error);
}
});
}
Below is the 'config.service.spec.ts' code. Please let me know how to cover the subscribe error part for the same.
it('coverage for getConfiguration()', () => {
const service: ConfigService = Testbed.get(ConfigService);
const param = {id: 10};
const response = {success: true};
const httpService: HttpService = Testbed.get(HttpService);
spyOn(httpService, 'post').and.returnValue(of(response));
service.getConfiguration(param).then(function() {});
expect(service.getConfiguration).toBeTruthy();
});
Here the observable error part is not covering and unable to reach the coverage. Kindly correct me if anything wrong here.