Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redux-logger getting used within redux-mock-store? #54

Closed
brotzky opened this issue Jul 6, 2016 · 4 comments
Closed

redux-logger getting used within redux-mock-store? #54

brotzky opened this issue Jul 6, 2016 · 4 comments

Comments

@brotzky
Copy link

brotzky commented Jul 6, 2016

In my regular application I have:

import createLogger from 'redux-logger';

const logger = createLogger();

const enhancer = compose(
  applyMiddleware(thunk, logger),
  persistState(
    window.location.href.match(
      /[?&]debug_session=([^&#]+)\b/
    )
  )
);

export default function configureStore(initialState) {
  const store = createStore(rootReducer, initialState, enhancer);

  if (module.hot) {
    module.hot.accept('../reducer', () => {
      store.replaceReducer(require('../reducer').default);
    });
  }

  return store;

But within my tests I have

import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import fetchMock from 'fetch-mock';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

But in my terinal window and withink Karma's Chrome Browser I am getting redux-logger details printed out. LOG: '%c prev state', 'color: #9E9E9E; font-weight: bold', Object{auth: Object{accessToken: null, userId: null, isAuthenticated: false, isAuthenticating: false, statusText: null}, form: Object{}, header: Object{showAside: false}, routing: Object{locationBeforeTransitions: null}, user: Object{isFetching: false, errors: []}}

I'm not adding redux-logger to my configureMockStore, only my real store which I am not using for my tests. Is there any way to get rid of redux-logger for tests?

@dmitry-zaets
Copy link
Collaborator

How do you use mockStore then? Do you pass an initial state?

@brotzky brotzky closed this as completed Jul 13, 2016
@Descartess
Copy link

@brotzky did you find a solution to this issue

@brotzky
Copy link
Author

brotzky commented Sep 19, 2017

@Descartess It's possible, but I've completely forgotten if I did. Sorry :(

@hoscarcito
Copy link

Sorry to open this, but this is happening to me now.
Practically the same config as @brotzky

Part of one of my tests:

import React from 'react';
import { shallow } from 'enzyme/build';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import Trucks from '../.';

describe('Trucks', () => {
  const initialState = {
    trucks: {
      loading: false,
      trucks: [],
      truck: {}
    },
    global: { accountName: 'Juaniten' }
  };

  const props = {
    match: { params: { accountID: 1 } }
  }

  const middlewares = [ thunk ];
  const mockStore = configureStore(middlewares);

  let store;
  let wrapper;
  let component;

  beforeEach(() => {
    store = mockStore(initialState);
    store.dispatch = jest.fn().mockName('mockDispatch');
    component = shallow(<Trucks store={store} {...props} />);
    wrapper = component.dive().dive();
  });

If I remove the logger in the createStore of the app, the test stop showing those logs on the console.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants