diff --git a/src/react/AppProvider.jsx b/src/react/AppProvider.jsx index 74f9e8795..f9fbd4574 100644 --- a/src/react/AppProvider.jsx +++ b/src/react/AppProvider.jsx @@ -43,7 +43,7 @@ import { * @param {Object} [props.store] A redux store. * @memberof module:React */ -export default function AppProvider({ store, children }) { +export default function AppProvider({ store, children, wrapInRouter }) { const [config, setConfig] = useState(getConfig()); const [authenticatedUser, setAuthenticatedUser] = useState(getAuthenticatedUser()); const [locale, setLocale] = useState(getLocale()); @@ -71,9 +71,11 @@ export default function AppProvider({ store, children }) { value={appContextValue} > - - {children} - + {wrapInRouter ? ( + + {children} + + ) : children} @@ -85,8 +87,10 @@ AppProvider.propTypes = { // eslint-disable-next-line react/forbid-prop-types store: PropTypes.object, children: PropTypes.node.isRequired, + wrapInRouter: PropTypes.bool, }; AppProvider.defaultProps = { store: null, + wrapInRouter: true, }; diff --git a/src/react/AppProvider.test.jsx b/src/react/AppProvider.test.jsx index 67ab6910b..955bb9b22 100644 --- a/src/react/AppProvider.test.jsx +++ b/src/react/AppProvider.test.jsx @@ -1,6 +1,7 @@ import React from 'react'; import { createStore } from 'redux'; import { mount } from 'enzyme'; +import { BrowserRouter as Router } from 'react-router-dom'; import AppProvider from './AppProvider'; import { initialize } from '../initialize'; @@ -48,7 +49,7 @@ describe('AppProvider', () => { }); }); - it('should render its children', () => { + it('should render its children with a router', () => { const component = ( state)}>
Child One
@@ -58,6 +59,26 @@ describe('AppProvider', () => { const wrapper = mount(component); const list = wrapper.find('div'); + expect(wrapper.find(Router).length).toEqual(1); + expect(list.length).toEqual(2); + expect(list.at(0).text()).toEqual('Child One'); + expect(list.at(1).text()).toEqual('Child Two'); + + const reduxProvider = wrapper.find('Provider'); + expect(reduxProvider.length).toEqual(1); + }); + + it('should render its children without a router', () => { + const component = ( + state)} wrapInRouter={false}> +
Child One
+
Child Two
+
+ ); + + const wrapper = mount(component); + const list = wrapper.find('div'); + expect(wrapper.find(Router).length).toEqual(0); expect(list.length).toEqual(2); expect(list.at(0).text()).toEqual('Child One'); expect(list.at(1).text()).toEqual('Child Two');