我必须测试组件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