test cases - effects.helpers
ADD
src/effects/effects.helpers.spec.ts
+import { mapTo } from 'rxjs/operators';
+import { isEffect, isGroup } from './effects.helpers';
+import { Effect, GroupedEffects } from './effects.interface';
+
+describe('Effects helpers', () => {
+
+ it('#isGroup checks if parameters is GroupedEffects type', () => {
+ expect(isGroup({ path: '/test', effects: [] })).toBe(true);
+ expect(isGroup({ path: '/test', effects: {} } as GroupedEffects)).toBe(false);
+ expect(isGroup({ path: '/test', effects: {} } as GroupedEffects)).toBe(false);
+ expect(isGroup({ effects: [] } as any as GroupedEffects)).toBe(false);
+ });
+
+ it('#isEffect checks if parameters is GroupedEffects type', () => {
+ const effect$: Effect = request$ => request$.pipe(mapTo({}));
+ const groupedEffects = { path: '/test', effects: [effect$] };
+
+ expect(isEffect(effect$)).toBe(true);
+ expect(isEffect(groupedEffects)).toBe(false);
+ });
+});

MODIFY
src/effects/effects.helpers.ts
src/effects/effects.helpers.ts
import { Effect, EffectResponse, GroupedEffects } from './effects.interface';
-export const isGroup = (item): item is GroupedEffects =>
- typeof item === 'object' && !!item.path && !!item.effects;
+export const isGroup = (item: Effect | GroupedEffects): item is GroupedEffects =>
+ typeof item === 'object'
+ && !!item.path
+ && !!item.effects
+ && typeof item.path === 'string'
+ && Array.isArray(item.effects);
-export const isEffect = (item): item is Effect<EffectResponse> =>
- !isGroup(item);
+export const isEffect = (item: Effect | GroupedEffects): item is Effect<EffectResponse> =>
+ !isGroup(item)
+ && typeof item === 'function';

test cases - effects.helpers