【发布时间】:2018-05-05 03:59:56
【问题描述】:
我有一个函数,它依赖于参数返回组件或 null。我创建了一个对象数组,其中包含应返回的参数和组件。如何检查我使用 switch/case 语句返回的内容。
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
}
}
测试
describe.only('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', () => {
const result = getMiConfiguration(id)
}))
})
【问题讨论】:
标签: reactjs unit-testing ecmascript-6 mocha.js enzyme