Describe the bug
when yup.lazy() is used inside a parent schema, yup.default() not honored
To Reproduce
import * as yup from 'yup';
const schema = yup.object({
num: yup.number().default(123),
lazyNum: yup.lazy(() => yup.number().default(456))
})
it('should supply defaults in normal and lazy case', () => {
expect(schema.validateSync(undefined)).toEqual({
num: 123, // GOOD
lazyNum: 456 // FAILS: undefined,
})
});
Expected behavior
I'd expect {num: 123, lazyNum: 456} - but maybe I'm surely misunderstanding? Maybe this
is a doc issue, but is certainly surprising behavior (at least to me ;-)) but I still need a way to
have defaults combined with lazy schemas.
Additional context
- works fine if
yup.lazy() is the top-level schema (e.g. no outer object({})
- In this contrived test, we're ignoring the lazy
value - in my real-world, the lazy function is testing
typeof value etc.
Describe the bug
when yup.lazy() is used inside a parent schema, yup.default() not honored
To Reproduce
Expected behavior
I'd expect
{num: 123, lazyNum: 456}- but maybe I'm surely misunderstanding? Maybe thisis a doc issue, but is certainly surprising behavior (at least to me ;-)) but I still need a way to
have defaults combined with lazy schemas.
Additional context
yup.lazy()is the top-level schema (e.g. no outerobject({})value- in my real-world, the lazy function is testingtypeof valueetc.