import { render, RenderOptions } from '@testing-library/react'; import { merge } from 'immutable'; import React, { FC, ReactElement } from 'react'; import { IntlProvider } from 'react-intl'; import { Provider } from 'react-redux'; import { MemoryRouter } from 'react-router-dom'; import { Action, applyMiddleware, createStore } from 'redux'; import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; import '@testing-library/jest-dom'; import NotificationsContainer from '../features/ui/containers/notifications_container'; import { default as rootReducer } from '../reducers'; // Mock Redux // https://redux.js.org/recipes/writing-tests/ const middlewares = [thunk]; const mockStore = configureMockStore(middlewares); let rootState = rootReducer(undefined, {} as Action); // Apply actions to the state, one at a time const applyActions = (state: any, actions: any, reducer: any) => { return actions.reduce((state: any, action: any) => reducer(state, action), state); }; const createTestStore = (initialState: any) => createStore(rootReducer, initialState, applyMiddleware(thunk)); const TestApp: FC = ({ children, storeProps, routerProps = {} }) => { let store: any; if (storeProps) { rootState = merge(rootState, storeProps); store = createTestStore(rootState); } else { store = createTestStore(rootState); } const props = { locale: 'en', store, }; return ( {children} ); }; const customRender = ( ui: ReactElement, options?: Omit, store?: any, routerProps?: any, ) => render(ui, { wrapper: () => , ...options, }); export * from '@testing-library/react'; export { customRender as render, mockStore, applyActions, rootState, rootReducer, };