Let's write one more test. This time we will be testing the filter() operator. This one is interesting, as it filters away values that does not fulfill a certain condition. Our test file should now look like the following:
import { cold } from "jasmine-marbles";
import "rxjs/add/operator/map";
import "rxjs/add/operator/filter";
describe("marble testing", () => {
it("map - should increase by 1", () => {
const one$ = cold("x-x|", { x: 1 });
expect(one$.map(x => x + 1)).toBeObservable(cold("x-x|", { x: 2 }));
});
it("filter - should remove values", () => {
const stream$ = cold("x-y|", { x: 1, y: 2 });
expect(stream$.filter(x => x > 1)).toBeObservable(cold("--y|", { y: 2 }));
});
});
This test is set up in pretty much the same way as our first test. This time we use the filter() operator but what stands out is our expected stream:
cold("--y|", { y: 2 })
--y, means that our first values is removed. Based on how the filter condition is defined, we are not surprised. The reason for the double hyphen, -, though, is that time still passes, but instead of an emitted value a hyphen takes its place.
To learn more about Marble testing, have a look at the following link from the official documentation, https://github.com/ReactiveX/rxjs/blob/master/doc/writing-marble-tests.md