Reactjs 带react的酶开关盒

Reactjs 带react的酶开关盒,reactjs,unit-testing,ecmascript-6,mocha.js,enzyme,Reactjs,Unit Testing,Ecmascript 6,Mocha.js,Enzyme,我有一个函数,它依赖于返回组件或null的参数。我创建了一个对象数组,其中包含应返回的参数和组件。如何检查switch/case语句返回的内容 export const getMiConfiguration = miConfigurationType => { switch (miConfigurationType) { case MiConfigurationTypes.WanderingDetection : case MiConfigurati

我有一个函数,它依赖于返回组件或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
    }
} 
export const getMiConfiguration=miConfigurationType=>{
开关(微配置类型){
案例微配置类型.WanderingDetection:
案例MiConfigurationTypes.MuteWanderingDetection:
返回
案例MiConfigurationTypes.OpenWanderingControl:
案例MIConfiguration Types.LockedWanderingControl:
返回
违约:
返回空
}
} 
试验

description.only('getMiConfiguration',()=>{
;[{id:MiConfigurationTypes.AccessPointOnly,component:null},
{id:MiConfigurationTypes.WanderingDetection,组件:},
{id:MiConfigurationTypes.MuteWanderingDetection,组件:},
{id:MiConfigurationTypes.LockedWanderingControl,组件:},
{id:MiConfigurationTypes.OpenWanderingControl,组件:},
].forEach({id,component})=>
它('应该呈现正确的组件',()=>{
const result=getMiConfiguration(id)
}))
})

我将从循环中提取
it
方法,如:

describe.only('getMiConfiguration', () => {
    it('should render correct component', () => {
        [
            {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}) => {
            const result = getMiConfiguration(id);
            // your assertion
            expect(result).toBe('your expected value');
        })
    })
})
description.only('getMiConfiguration',()=>{
它('应该呈现正确的组件',()=>{
[
{id:MiConfigurationTypes.AccessPointOnly,组件:null},
{id:MiConfigurationTypes.WanderingDetection,组件:},
{id:MiConfigurationTypes.MuteWanderingDetection,组件:},
{id:MiConfigurationTypes.LockedWanderingControl,组件:},
{id:MiConfigurationTypes.OpenWanderingControl,组件:},
].forEach({id,component})=>{
const result=getMiConfiguration(id);
//你的主张
期望(结果)。托比(“你的期望值”);
})
})
})

这对我有帮助,但在测试redux表单时仍然存在问题

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)
        }))
})
description('getMiConfiguration',()=>{
;[{id:MiConfigurationTypes.AccessPointOnly,component:null},
{id:MiConfigurationTypes.WanderingDetection,组件:},
{id:MiConfigurationTypes.MuteWanderingDetection,组件:},
{id:MiConfigurationTypes.LockedWanderingControl,组件:},
{id:MiConfigurationTypes.OpenWanderingControl,组件:},
].forEach({id,component})=>
它(`should render correct${component}component for${id}type`,()=>{
const result=getMiConfiguration(id)
如果(组件===null)
expect(result).to.be.null
其他的
result.type.should.be.equal(component.type)
}))
})

要用于true或false语句,我需要在MiConfigurationTypes.AccessPointOnly时检查null
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)
        }))
})