I imagine your full case resembles something like this
// first there is something that emits an Observable
export function doSomethingThatReturnsAnObservable() {
return createSomehowFirstObservable()
.pipe(
// then you take the data emitted by the first Observable
// and try to do something else which will emit another Observable
// therefore you have to use an operator like concatMap or switchMap
// this something else is where your error condition can occur
// and it is where we use your getSomeData() function
switchMap(inputValue => getSomeData(inputValue))
);
}
}
// eventually, somewhere else, you subscribe
doSomethingThatReturnsAnObservable()
.subscribe(
data => doStuff(data),
error => handleError(error),
() => doSomethingWhenCompleted()
)
A test for the error condition could look something like this
it('test error condition'), done => {
// create the context so that the call to the code generates an error condition
.....
doSomethingThatReturnsAnObservable()
.subscribe(
null, // you are not interested in the case something is emitted
error => {
expect(error).to.equal(....);
done();
},
() => {
// this code should not be executed since an error condition is expected
done('Error, the Observable is expected to error and not complete');
}
)
})
jasmine-marbles
is a completely different library that does not have to be used nor it is used in my answer. I wouldn't even recommend using the library - I've had so many problems using it, especially with time progression, so I'd still stick with the official and recommended way of writing RxJS unit tests. – Trematode