test cases - matchType.operator
ADD
src/operators/matchType.operator.spec.ts
+import { HttpRequest } from '../http.interface';
+import { Marbles } from '../util/marbles.spec-util';
+import { matchType } from './matchType.operator';
+
+const createMockReq = (method: string) => ({ method } as HttpRequest);
+
+describe('matchType operator', () => {
+
+ it('filters GET request stream', () => {
+ const operators = [matchType('GET')];
+ Marbles.assert(operators, [
+ ['-a-b---', { a: createMockReq('GET'), b: createMockReq('POST') }],
+ ['-a-----', { a: createMockReq('GET') }],
+ ]);
+ });
+
+ it('filters POST request stream', () => {
+ const operators = [matchType('POST')];
+ Marbles.assert(operators, [
+ ['-a-b---', { a: createMockReq('GET'), b: createMockReq('POST') }],
+ ['---b---', { b: createMockReq('POST') }],
+ ]);
+ });
+
+});

MODIFY
src/util/marbles.spec-util.ts
src/util/marbles.spec-util.ts
-import { Observable, from } from 'rxjs';
+import { Observable, OperatorFunction, from } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { Effect, EffectResponse } from '../effects/effects.interface';
import { HttpRequest, HttpResponse } from '../http.interface';
@@ -15,6 +15,25 @@ export namespace Marbles {
const createTestScheduler = () =>
new TestScheduler(deepEquals);
+ export const assert = <T>(
+ operators: OperatorFunction<T, any>[],
+ marbleflow: [MarbleFlow, MarbleFlow]
+ ) => {
+ const [initStream, initValues] = marbleflow[0];
+ const [expectedStream, expectedValues] = marbleflow[1];
+
+ const scheduler = createTestScheduler();
+ const observable = scheduler.createColdObservable(initStream, initValues);
+ const stream = from(observable) as Observable<T>;
+ const pipedStream = stream.pipe(...operators);
+
+ scheduler
+ .expectObservable(pipedStream)
+ .toBe(expectedStream, expectedValues);
+
+ scheduler.flush();
+ };
+
export const assertEffect = (
effect: Effect,
marbleflow: [MarbleFlow, MarbleFlow],

test cases - matchType.operator