jquense / yup

Dead simple Object schema validation
MIT License
22.95k stars 935 forks source link

validateAt value for numeric field is always zero in test method #2092

Closed Chrisposure closed 1 year ago

Chrisposure commented 1 year ago

Calling validateAt for a numeric field currently always comes with a numeric zero value into the test method:

` // validateAt call: await mySchema.validateAt('numericField', 4, { context: { optionA: 'A' } })

// test method: const myTest = (value: number, context: TestContext) => { console.log(value) // value is always ZERO! }

// schema: const mySpec = { numericField: number().label('Numeric Field').required().default(0).test('MY-TEST', myTest),
} const mySchema: ObjectSchema = object(mySpec ).strict(true)`

When I call isValid directly on the spec the value is correct:

await mySpec.numericField.isValid(4, { context: { optionA: 'A' } })

What am I doing wrong?

jquense commented 1 year ago

yes, validateAt, expects a root value, not the field value. Please double check your usage against the documentation: https://github.com/jquense/yup#schemavalidateatpath-string-value-any-options-object-promiseinfertypeschema-validationerror