Having trouble with my function and spec test, as it is failing with the error:
Unhandled promise rejection: [object Object]
Function:
someFunction(a,b,c) {
var dfd = q.defer();
this.getInfo(b,c).then((data)=> {
//do Something
dfd.resolve(data);
}).catch((error)=> {
dfd.reject(error)
})
return dfd.promise;
}
Spec Test:
describe( 'SomeFunction', () => {
it( 'should reject when getInfo request fails', ( done ) => {
spyOn( utility, 'getInfo' ).and.callFake( async () => {
var deferred = q.defer();
deferred.reject( { error: 500 } );
return deferred.promise;
});
let promise = utility.someFunction( a,b,c );
expect(utility.getInfo).toHaveBeenCalled();
promise.then().catch( function ( data:any) {
expect( data ).toEqual( { error: 500 } );
} ).finally( done );
});
I'm trying to write a test case for reject but keep getting an unhandled promise rejection error. If anyone could help, I'd appreciate it.