diff --git a/src/helpers/Authorize.jsx b/src/helpers/Authorize.jsx index d8415874d39815dbb1f8a8c896f5288b4fe01b4d..3c6322812a65872bcfc2576a9694baa5a30e00e2 100644 --- a/src/helpers/Authorize.jsx +++ b/src/helpers/Authorize.jsx @@ -41,7 +41,7 @@ export class Authorize extends React.Component { render() { return this.state.authorized - ? <div>{this.props.children}</div> + ? this.props.children : this.props.unauthorized || null } } diff --git a/test/helpers/Authorize.test.jsx b/test/helpers/Authorize.test.jsx index cb0c27f929050801a74cd9e635f1eacdc0f3b233..e02eacee80985916fb8937b0beda995a0dee738d 100644 --- a/test/helpers/Authorize.test.jsx +++ b/test/helpers/Authorize.test.jsx @@ -8,8 +8,7 @@ global.PUBSWEET_COMPONENTS = [] function makeWrapper(props = {}) { return shallow( <Authorize currentUser={{ id: 'user1' }} {...props}> - <span className="secret" /> - <span className="sibling" /> + <div /> </Authorize>, ) } @@ -45,12 +44,11 @@ describe('<Authorize/>', () => { }) it('optionally shows alternative content when not authorized', async () => { - const wrapper = makeWrapper({ authsome, unauthorized: <span className="message" /> }) + const wrapper = makeWrapper({ authsome, unauthorized: <span /> }) resolveMode(false) await modePromise - expect(wrapper.find('.secret')).toHaveLength(0) - expect(wrapper.find('.message')).toHaveLength(1) + expect(wrapper.type()).toBe('span') }) it('is empty when authsome throws', async () => { @@ -74,7 +72,7 @@ describe('<Authorize/>', () => { resolveMode(true) await modePromise - expect(wrapper.find('.secret')).toHaveLength(1) + expect(wrapper.type()).toBe('div') }) it('rechecks auth when props change', () => {