Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date().required() does not validate correctly within when() #399

Closed
pcorey opened this issue Dec 12, 2018 · 1 comment
Closed

date().required() does not validate correctly within when() #399

pcorey opened this issue Dec 12, 2018 · 1 comment
Labels

Comments

@pcorey
Copy link

pcorey commented Dec 12, 2018

Given this code:

const { date, mixed, object, string } = require('yup');

const schema = object().shape({
    foo: string(),
    date: mixed().when('foo', {
        is: 'bar',
        then: date().required()
    })
});

console.log(schema.validateSync({ foo: 'boo' }));
console.log(schema.validateSync({ foo: 'bar', date: '123' }));
console.log(schema.validateSync({ foo: 'bar', date: 'hi' }));

The first two calls to schema.validateSync pass, as expected. The third call that validates { foo: 'bar', date: 'hi' } also passes validation, which seems wrong. 'hi' is not a valid date, and date() wouldn't accept this value outside of a while() block.

I'm on yup@0.26.6.

@jquense
Copy link
Owner

jquense commented Dec 13, 2018

Seems like a bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants