Exercise - Error
Exercise
In this exercise we will create two tests that assert error notifications.
The first test will assert that the source Observable emits an error notification:
- Open exercise on codesandbox.
I've already imported the
TestScheduler
class and set up the test. - Invoke the
run()
method of theTestScheduler
instance. You'll need thecold
andexpectObservable
properties from theRunHelper
object that is passed to the callback function. - Create a new
source
cold Observable using thecold()
function. The source Observable emits a next notification on frame 100, and then an error notification on frame 200. - Define the
expected
string that represents the behavior of the source cold Observable. - Use the
expectObservable()
function to create the assertion.
The second test will use a source
Observable from an interval()
that uses the throwError()
operator when the value is greater than 0
.
Here is the source Observable:
const source = interval(100).pipe(
mergeMap((value) => {
if (value > 0) {
return throwError('error');
}
return of(value);
})
);
Write a unit test for this source Observable.