Skip to content

Commit

Permalink
Merge pull request #11 from mediamonks/feature/duplicate-warning
Browse files Browse the repository at this point in the history
Replace duplicate name error with console.warn
  • Loading branch information
flut1 authored May 25, 2017
2 parents b1bfe51 + 35e1656 commit 0a38fb3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"react/jsx-filename-extension": 0,
"linebreak-style": 0,
"no-underscore-dangle": 0,
"no-console": 0,
"import/first": "off",
"import/order": ["error", {
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
Expand Down
2 changes: 1 addition & 1 deletion src/withInitAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default (p1, p2, p3) => {
throw new Error('withInitAction() HoC requires the wrapped component to have a displayName');
}
if (componentIds.includes(componentId)) {
throw new Error(`Each Component passed to withInitAction() should have a unique displayName. Found duplicate name "${componentId}"`);
console.warn(`Each Component passed to withInitAction() should have a unique displayName. Found duplicate name "${componentId}"`);
}
componentIds.push(componentId);

Expand Down
26 changes: 0 additions & 26 deletions tests/withInitAction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,4 @@ describe('withInitAction', () => {
)(FooComponent);
expect(WithInit.initConfig.initProps).toEqual(['a', 'b', 'c']);
});

it('throws an error when two components with the same displayName are passed', () => {
clearComponentIds();
class BarComponent extends Component {
render() {
return <noscript />;
}
}

class BarComponent2 extends Component {
static displayName = 'BarComponent';

render() {
return <noscript />;
}
}

// eslint-disable-next-line no-unused-vars
const WithInit = withInitAction(() => Promise.resolve())(BarComponent);
expect(() => {
// eslint-disable-next-line no-unused-vars
const WithInit2 = withInitAction(
() => Promise.resolve(),
)(BarComponent2);
}).toThrow();
});
});

0 comments on commit 0a38fb3

Please sign in to comment.