LiveLoveApp logo

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:

  1. Open exercise on codesandbox. I've already imported the TestScheduler class and set up the test.
  2. Invoke the run() method of the TestScheduler instance. You'll need the cold and expectObservable properties from the RunHelper object that is passed to the callback function.
  3. Create a new source cold Observable using the cold() function. The source Observable emits a next notification on frame 100, and then an error notification on frame 200.
  4. Define the expected string that represents the behavior of the source cold Observable.
  5. 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.