Ask Your Question

Revision history [back]

The process for testing an infinite stream using Jasmine Marbles has several steps:

  1. First, import the necessary modules into your test file:
import { TestScheduler } from 'rxjs/testing';
import { cold } from 'jasmine-marbles';
  1. Create a new instance of the TestScheduler class:
const scheduler = new TestScheduler((actual, expected) => {
  expect(actual).toEqual(expected);
});
  1. Define your input stream using the cold function from jasmine-marbles. This function takes a string as its argument, representing the values emitted by the stream over time. For example:
const input = cold('a-b-c-d-|');
  1. Define your expected output stream using a similar cold function:
const expectedOutput = cold('a-b-c-d-|');
  1. Subscribe to your input stream and expect it to equal your expected output using the expectObservable function:
scheduler.expectObservable(input).toBe(expectedOutput);
  1. Finally, flush the test scheduler to execute the test:
scheduler.flush();

This will test whether the input stream emits the expected values at the expected times.