反应最终形式FieldProps-验证:如何访问“值”对象

时间:2018-08-07 08:17:04

标签: reactjs jestjs enzyme

我必须测试组件Comp:

> export const Comp = ({ index, dec, ...props }) => (   <Field
>     component={InputField2}
>     validate={props.disabled ? undefined : validateComp(dec)(index)}
>     type="text"
>     {...props}   /> )

验证功能

> export const validateComp = dec => index => (value, values) => {   
> const listOfValidations = [
>     isNonNegative(),
>     isDecimalPlacesNotGreaterThan(`Decimals should not exceed ${decimals} places`)(decimals),
>     isLessOrEqualThan(`Should be less or equal than  supply (${values.tier[index].supply})`)(
>       values.tier[index].supply
>     )   ]
> 
>   return composeValidators(...listOfValidations)(value) }

但是我什至无法渲染它,因为道具{validation}中的validateComp函数没有明确地使用values。结果是values未定义和validateComp函数总是失败。

我的测试:

> it(`should render`, () => {
>     const wrapper = mount(
>       <Form
>         onSubmit={ jest.fn() }
>         component={Comp}
>         name="comp"
>         decimals={18}
>         index={0}
>         disabled={false}
>       />
>     )

问:如何设置验证功能的值? https://github.com/final-form/final-form#validate-values-object--object--promiseobject

0 个答案:

没有答案