Permalink
Browse files

feat(combineEpics): verbose combineEpics returned function name (#480)

Combined functions always return `<anonymous>` which is not very useful. This Commit updates the name of the combined epics to the following:

> combineEpics(epic1, epic2)

style(combineEpics): shorter code

style(combineEpics): fix linting

fallback to '<anonymous>'

add unit tests
  • Loading branch information...
Bamieh authored and jayphelps committed May 9, 2018
1 parent 592da27 commit 816a9163074943508de1300d3e1ca39603568186
Showing with 31 additions and 2 deletions.
  1. +7 −2 src/combineEpics.js
  2. +24 −0 test/combineEpics-spec.js
@@ -3,8 +3,8 @@ import { merge } from 'rxjs';
/**
Merges all epics into a single one.
*/
export const combineEpics = (...epics) => (...args) =>
merge(
export const combineEpics = (...epics) => {
const merger = (...args) => merge(
...epics.map(epic => {
const output$ = epic(...args);
if (!output$) {
@@ -13,3 +13,8 @@ export const combineEpics = (...epics) => (...args) =>
return output$;
})
);

return Object.defineProperty(merger, 'name', {
value: `combineEpics(${epics.map(epic => epic.name || '<anonymous>').join(', ')})`,
});
};
@@ -71,4 +71,28 @@ describe('combineEpics', () => {
rootEpic();
}).to.throw('combineEpics: one of the provided Epics "epic2" does not return a stream. Double check you\'re not missing a return statement!');
});

describe('returned epic function name', () => {
const epic1 = () => 'named epic';
const epic2 = () => 'named epic';
const epic3 = () => 'named epic';

it('should name the new epic with `combineEpics(...epic names)`', () => {
const rootEpic = combineEpics(epic1, epic2);

expect(rootEpic).to.have.property('name').that.equals('combineEpics(epic1, epic2)');
});

it('should annotate combined anonymous epics with `<anonymous>`', () => {
const rootEpic = combineEpics(() => 'anonymous', epic2);

expect(rootEpic).to.have.property('name').that.equals('combineEpics(<anonymous>, epic2)');
});

it('should include all combined epic names in the returned epic', () => {
const rootEpic = combineEpics(epic1, epic2, epic3);

expect(rootEpic).to.have.property('name').that.equals('combineEpics(epic1, epic2, epic3)');
});
});
});

0 comments on commit 816a916

Please sign in to comment.