How to use redux-mock-store - 10 common examples

To help you get started, we’ve selected a few redux-mock-store examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shopgate / pwa / themes / theme-ios11 / pages / WriteReview / components / ReviewForm / spec.jsx View on Github external
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import { mount } from 'enzyme';
import { LoadingProvider } from '@shopgate/pwa-common/providers';
import mockRenderOptions from '@shopgate/pwa-common/helpers/mocks/mockRenderOptions';
import { getCurrentRoute } from '@shopgate/pwa-common/helpers/router';
import {
  mockProductId,
  mockedStateWithoutReview,
  mockedStateWithInvalidReview,
  mockedStateWithReview,
  mockedStateWithUserReviewLoading,
  mockedStateWithoutProductData,
} from '../../mock';

const mockedStore = configureStore();

jest.mock('@shopgate/pwa-common/helpers/router', () => ({
  getCurrentRoute: jest.fn(),
}));

/**
 * Creates component with provided store state.
 * @param {Object} mockedState Mocked stage.
 * @param {Function} dispatchSpy Dispatch spy
 * @return {ReactWrapper}
 */
const createComponent = (mockedState, dispatchSpy = jest.fn()) => {
  /* eslint-disable global-require */
  const ReviewForm = require('./index').default;
  const store = mockedStore(mockedState);
  store.dispatch = dispatchSpy;
github FullstackAcademy / fsg / generated / browser / redux / modules / auth / spec.js View on Github external
'use strict';

import { expect } from 'chai';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import promise from '../../middleware/promise';
import reducer from '../auth';
import * as test from './tests';

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

describe('MODULE - auth:', () => {
  describe('ACTIONS', () => {
    let store = mockStore({ session: {} });

    // isLoaded action test
    test.isLoaded(mockStore);

    // load action tests
    test.load(mockStore);

    // login action tests
    test.login(mockStore);

    // logout action tests
    test.logout(mockStore);
github LightningPeach / peach-wallet-desktop / test / unit / modules / channels.spec.js View on Github external
import { exceptions } from "config";
import {
    channelsActions as actions,
    channelsTypes as types,
    channelsOperations as operations,
    channelsSelectors as selectors,
} from "modules/channels";
import channelsReducer, { initStateChannels } from "modules/channels/reducers";
import { accountTypes } from "modules/account";
import { appTypes, appOperations } from "modules/app";
import { onChainOperations } from "modules/onchain";
import { db, errorPromise, successPromise } from "additional";

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

describe("Channels Unit Tests", () => {
    describe("Action creators", () => {
        let data;
        let expectedData;

        beforeEach(() => {
            data = "foo";
            expectedData = {
                payload: data,
                type: undefined,
            };
        });

        it("should create an action to set channels", () => {
            expectedData.type = types.SET_CHANNELS;
github Bit-Nation / BITNATION-Pangea-mobile / src / PangeaCore / __tests__ / UI / Key / Enter / index.js View on Github external
test('EnterKeyScreen renders correctly', () => {
  const initialStateMock = {
    key: initialState,
    testingMode: { isActive: false },
  };
  const storeMock = configureStore([]);
  const propsMock = {
    navigator: navigatorMock,
  };

  const wrapper = shallow((
    
  ));
  expect(wrapper).toMatchSnapshot();
});
github GravityPDF / gravity-pdf / tests / mocha / unit-tests / components / Template / template.list.spec.js View on Github external
import React from 'react'
import { mount } from 'enzyme'
import { Provider } from 'react-redux'
import configureStore from 'redux-mock-store'
import { HashRouter as Router } from 'react-router-dom'

const mockStore = configureStore()

import { TemplateList } from '../../../../../src/assets/js/react/components/Template/TemplateList'

describe('', () => {

  it('our template container, search bar and single template item should be displayed', () => {
    const comp = mount(
      
        
      
    )

    const wrapper = comp.render()

    expect(wrapper.find('.theme-backdrop')).has.length(1)
github fossasia / susi.ai / src / __tests__ / components / Auth / ChangePassword / ChangePassword.js View on Github external
import React from 'react';
import ChangePassword from '../../../../components/Auth/ChangePassword/ChangePassword.react';
import { shallow } from 'enzyme';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
const mockStore = configureMockStore();
const store = mockStore({});

describe('', () => {
  it('render ChangePassword without crashing', () => {
    shallow(
      
        
      ,
    );
  });
});
github netlify / netlify-cms / packages / netlify-cms-core / src / actions / __tests__ / entries.spec.js View on Github external
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

jest.mock('coreSrc/backend');
jest.mock('../media', () => {
  const media = jest.requireActual('../media');
  return {
    ...media,
    getAsset: jest.fn(),
  };
});
jest.mock('netlify-cms-lib-util');
jest.mock('../mediaLibrary');

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

describe('entries', () => {
  describe('createEmptyDraftData', () => {
    it('should set default value for list field widget', () => {
      const fields = fromJS([
        {
          name: 'images',
          widget: 'list',
          field: { name: 'url', widget: 'text', default: 'https://image.png' },
        },
      ]);
      expect(createEmptyDraftData(fields)).toEqual({ images: ['https://image.png'] });
    });

    it('should set default values for list fields widget', () => {
      const fields = fromJS([
github pburtchaell / redux-promise-middleware / test / index.spec.js View on Github external
it('allows global customisation of rejected action `type`', () => {
      const mockStore = configureStore([
        promiseMiddleware({
          promiseTypeSuffixes: ['', '', customPrefix]
        }),
      ]);

      const expectedRejectAction = {
        type: `${promiseAction.type}_${customPrefix}`,
        error: rejectedAction.error,
        payload: rejectedAction.payload,
      };

      const store = mockStore({});

      return store.dispatch(promiseAction).catch(() => {
        expect(store.getActions()).to.include(expectedRejectAction);
      });
github shakacode / reactrails-react-native-client / __tests__ / bundles / comments / thunks / createComment.js View on Github external
it('creates a comment in the store and sends request to api', async() => {
    const data = {
      commentsStore: {},
      commentForm: { author: 'Alexey', text: 'Random comment' },
    };
    const store = createStoreFromState(fromJS(data));
    const response = {
      entities: {
        comments: {
          1: { id: 1, author: 'Alexey', text: 'Random comment' },
        },
      },
    };
    mockCalls(null, response);
    await store.dispatch(actions.createComment());
    expect(store.getActions()).toMatchSnapshot();
  });
});
github shakacode / reactrails-react-native-client / __tests__ / bundles / comments / hocs / withAddProps.js View on Github external
it('adds AddProps to a component', () => {
    const state = initialState.mergeDeep({
      commentForm: {
        author: 'Alexey',
        text: 'Random comment',
      },
    });
    const store = createStoreFromState(state);
    const Component = withAddProps(Mock);
    const tree = renderer.create();
    expect(tree).toMatchSnapshot();
  });
});

redux-mock-store

A mock store for testing your redux async action creators and middleware

MIT
Latest version published 2 months ago

Package Health Score

86 / 100
Full package analysis

Similar packages