redux-form单元测试字段值

时间:2017-11-27 14:12:41

标签: reactjs unit-testing redux redux-form enzyme

我用酶来测试redux-form的FIeld值取决于道具。如何在传递新道具时测试Field值。似乎Field的组件prop中的值。无论如何如何从redux形式测试Field,当设置新的道具时。有可能测试。看起来像redux表单测试字段值,我们不需要它,是吗?

<Field
    component={renderTextField}
    name='name'
    label={<FormattedMessage id='name' />}
/>

describe('EditDevice', () => {
    let page, push, handleSubmit, init
    let skip = {}
    let update = sinon.stub().resolves({success: true})
    let device = {
        deviceType: deviceTypes.MiAccessPoint,
        deviceId: 1,
        lastAliveMessage: 'some text',
        miConfiguration: {
            fieldRange: '',
            doorConfiguration: {},
        },
    }

    beforeEach(() => page = shallow(<EditDevice
        update={update}
        handleSubmit={sinon.spy()}
        deviceId={deviceId}
        history={{push: push = sinon.spy()}}
        skip={skip}
        initialValues={device}
    />))



  it.only('should update device fields if isLoadingInProgress turned from true to false on receiving new props', async () => {
        const device = {
            name: 'new name',
            deviceType: deviceTypes.Tag,
            version: 'new version',
            deviceStatus: 'online',
        }

        page.setProps({isLoadingInProgress: true})
        page.setProps({isLoadingInProgress: false, initialValues:{...device}})
        page.update()
        page.find(Field).findWhere(x => x.props().name === 'name').props().value.should.be.equal(device.name)

    })

0 个答案:

没有答案