My interpretation of the entire scenario might be something along these lines
// Initially, there is a process that emits an Observable
export function executeObservableProcess() {
return initiateInitialObservable()
.pipe(
// Subsequently, you handle the data emitted by the first Observable
// and proceed to another operation that will result in emission of another Observable
// This requires the use of operators like concatMap or switchMap
// This secondary operation is where errors may occur,
// and this is where your getSomeData() function comes into play
switchMap(input => fetchData(input))
);
}
}
// At some point later, you subscribe to the Observable
executeObservableProcess()
.subscribe(
results => performActions(results),
error => handleErrors(error),
() => finalizeExecution()
)
A typical test for error scenarios could be formulated as shown below
it('test error condition'), done => {
// Set up the necessary context to trigger an error condition during execution
.....
executeObservableProcess()
.subscribe(
null, // You are not interested in emitted values
error => {
expect(error).to.equal(....);
done();
},
() => {
// The code here should ideally not run since we anticipate an error condition
done('Error: The Observable is supposed to throw an error instead of completing successfully');
}
)
})