UNPKG

contiago-toolbar

Version:

One of the options for outputting content from contiago xml-server

56 lines (43 loc) 1.61 kB
/** * Test injectors */ import { memoryHistory } from 'react-router-dom'; import { shallow } from 'enzyme'; import React from 'react'; import identity from 'lodash/identity'; import configureStore from '../../configureStore'; import injectReducer from '../injectReducer'; import * as reducerInjectors from '../reducerInjectors'; // Fixtures const Component = () => null; const reducer = identity; describe('injectReducer decorator', () => { let store; let injectors; let ComponentWithReducer; beforeAll(() => { reducerInjectors.default = jest.fn().mockImplementation(() => injectors); }); beforeEach(() => { store = configureStore({}, memoryHistory); injectors = { injectReducer: jest.fn(), }; ComponentWithReducer = injectReducer({ key: 'test', reducer })(Component); reducerInjectors.default.mockClear(); }); it('should inject a given reducer', () => { shallow(<ComponentWithReducer />, { context: { store } }); expect(injectors.injectReducer).toHaveBeenCalledTimes(1); expect(injectors.injectReducer).toHaveBeenCalledWith('test', reducer); }); it('should set a correct display name', () => { expect(ComponentWithReducer.displayName).toBe('withReducer(Component)'); expect(injectReducer({ key: 'test', reducer })(() => null).displayName).toBe('withReducer(Component)'); }); it('should propagate props', () => { const props = { testProp: 'test' }; const renderedComponent = shallow(<ComponentWithReducer {...props} />, { context: { store } }); expect(renderedComponent.prop('testProp')).toBe('test'); }); });