Skip to content

Commit

Permalink
Remove warning on 'redundant' prepareComponent()
Browse files Browse the repository at this point in the history
We might want to keep prepareComponent() calls around when
refactoring to clientOnly, just so it is easy to refactor back.
For that reason we shouldn't spam the console.
  • Loading branch information
Floris Bernard committed Dec 14, 2018
1 parent 34ca6cb commit 4f9dcb3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 44 deletions.
6 changes: 0 additions & 6 deletions src/actions/prepareComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ export default (Component, props = {}) => (dispatch, getState) => {

const prepareKey = getPrepareKey(componentId, initValues);

if (!initAction && initActionClient) {
console.warn(
`Redundant call to prepareComponent() with component "${componentId}". Initialization is client-only, so preparing is not neccessary`,
);
}

return dispatch(
initComponent(Component, initValues, prepareKey, {
caller: 'prepareComponent',
Expand Down
38 changes: 0 additions & 38 deletions tests/actions/prepareComponent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,42 +171,4 @@ describe('prepareComponent', () => {
expect(actions).toEqual([]);
}));
});

it('warns the user about redundant calls with clientOnly initAction components', () => {
clearComponentIds();
const store = mockStore(modePrepareAndNothingPrepared);
const mockInitActionClient = jest.fn(() => Promise.resolve());
const MockWithInit = withInitAction(
{
clientOnly: mockInitActionClient,
},
)(SimpleInitTestComponent);
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});

const preparePromise = store.dispatch(prepareComponent(MockWithInit, {}));
return preparePromise.then(() => {
expect(consoleWarnSpy).toHaveBeenCalled();
consoleWarnSpy.mockRestore();
});
});

it('does not warn the user if there is a prepared action', () => {
clearComponentIds();
const store = mockStore(modePrepareAndNothingPrepared);
const mockInitActionPrepared = jest.fn(() => Promise.resolve());
const mockInitActionClient = jest.fn(() => Promise.resolve());
const MockWithInit = withInitAction(
{
prepared: mockInitActionPrepared,
clientOnly: mockInitActionClient,
},
)(SimpleInitTestComponent);
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});

const preparePromise = store.dispatch(prepareComponent(MockWithInit, {}));
return preparePromise.then(() => {
expect(consoleWarnSpy).not.toHaveBeenCalled();
consoleWarnSpy.mockRestore();
});
});
});

0 comments on commit 4f9dcb3

Please sign in to comment.