Redux Form单元测试

时间:2017-11-22 13:49:09

标签: ecmascript-6 redux chai redux-form enzyme

我尝试用酶将单元测试写入包含到redux-form w的组件,当我尝试测试一些渲染的组件时,我遇到了一个问题,取决于来自redux-form HOC的formValues HOC,如何测试和模拟存储或者道具从fromValues到组件。当然我有一些包含在HOC redux-form

中的父元素
 export const MiConfiguration = ({miConfiguration, change}) =>
{
    miConfiguration.isMiEnabled = miConfiguration.miConfigurationType !== MiConfigurationTypes.AccessPointOnly

    return <FormSection name='miConfiguration'>
        <Field
            name='miConfigurationType'
            component={renderSelectField}
            label={<FormattedMessage id='passage.label.scenario' />}
            style={{width: 400, ...styles.selectField}}
            hintText={<FormattedMessage id='passage.selectConfiguration.hint'/>}
            autoWidth
            onChange={(e, newValue) => Object.keys(defaultValues[newValue]).forEach(key => change(key, defaultValues[newValue][key]))}
        >
        {miConfiguration && !!miConfiguration.miConfigurationType &&
            <InfoMessage id={`miConfiguration.description.${miConfiguration.miConfigurationType}`} />}

    </FormSection>}

单元测试

describe('getMiConfiguration', () => {
    let component, onChange

    beforeEach(() => {
        component = shallow(<MiConfiguration miConfiguration={{}} change={onChange = sinon.spy()}/>)
    })

    it('should render <InfoMessage /> with id', () =>{
        component.setProps({miConfiguration: {miConfigurationType: 'type'})
component.find(InfoMessage).props().id.should.be.equal('some id')
        component.find(InfoMessage).should.exist})
})

0 个答案:

没有答案