bigbuffet-rw/app/soapbox/test_helpers.js

26 lines
918 B
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
import thunk from 'redux-thunk';
import renderer from 'react-test-renderer';
2020-06-09 20:04:22 -07:00
import { Provider } from 'react-redux';
import { IntlProvider } from 'react-intl';
import configureMockStore from 'redux-mock-store';
2020-06-09 20:04:22 -07:00
import { Map as ImmutableMap } from 'immutable';
// Mock Redux
// https://redux.js.org/recipes/writing-tests/
const middlewares = [thunk];
export const mockStore = configureMockStore(middlewares);
2020-06-09 20:04:22 -07:00
// Test Redux connected components
export const createComponentWithStore = (children, props = { store: mockStore(ImmutableMap()) }) => {
return renderer.create(<Provider {...props}>{children}</Provider>);
};
// Testing i18n components
// https://formatjs.io/docs/react-intl/testing/#helper-function-2
export const createComponentWithIntl = (children, props = { locale: 'en' }) => {
return renderer.create(<IntlProvider {...props}>{children}</IntlProvider>);
};