I've got a function that return depends on parameters HOC componetns. I wrraped this component to reduxForm HOC. I would like to test it with an enzyme using type(). The function returns HOC components with type FormValues, but how to return for test without HOC. How to test it with proxyquire
function
export const getMiConfiguration = miConfigurationType => {
switch (miConfigurationType) {
case MiConfigurationTypes.WanderingDetection :
case MiConfigurationTypes.MuteWanderingDetection:
return <WanderingDetection />
case MiConfigurationTypes.OpenWanderingControl :
case MiConfigurationTypes.LockedWanderingControl:
return <WanderingControl />
default:
return null
}
}
test
describe('getMiConfiguration', () => {
;[{id: MiConfigurationTypes.AccessPointOnly, component: null},
{id: MiConfigurationTypes.WanderingDetection, component: <WanderingDetection/>},
{id: MiConfigurationTypes.MuteWanderingDetection, component: <WanderingDetection/>},
{id: MiConfigurationTypes.LockedWanderingControl, component: <WanderingControl/>},
{id: MiConfigurationTypes.OpenWanderingControl, component: <WanderingControl/>},
].forEach(({id, component}) =>
it(`should render correct ${component} component for ${id} type`, () => {
const result = getMiConfiguration(id)
if (component === null)
expect(result).to.be.null
else
result.type.should.be.equal(component.type)
}))
})
example of a component
export const WanderingDetection = ({miConfigurationType}) =>
<Grid container>
<Grid item xs={12}>
<GeneralMiConfigurations />
</Grid>
{MiConfigurationTypes.MuteWanderingDetection === miConfigurationType &&
[
<Grid item xs={10} style={{margin: '0 auto'}}>
<Divider/>
</Grid>,
<Grid item xs={12} style={{alignSelf: 'center'}}>
<InfoMessage id='passage.label.useInputToMuteLocationField'/>
<InputTypeConfiguration/>
</Grid>,
]
}
</Grid>
WanderingDetection.propTypes = {
miConfigurationType: PropTypes.string,
}
export default formValues('miConfigurationType')(WanderingDetection)