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

key undefined when using validateAt #2270

Open
yuenhy opened this issue Feb 3, 2025 · 0 comments
Open

key undefined when using validateAt #2270

yuenhy opened this issue Feb 3, 2025 · 0 comments

Comments

@yuenhy
Copy link

yuenhy commented Feb 3, 2025

In my actual implementation code, I use testContext from validate to retrieve key, which enables me to access something in the context object.
However when writing unit tests, I can't access the key key with validateAt.

const nameValidation = yup.string().test('isOk', ({label}) => `${label} is not ok`, (value, testContext) => {
    const field = testContext.options.key;
    return field !== undefined;
});
const accountSchema = yup.object({
    name: nameValidation,
});

const account = {
    name: 'schemer',
};

accountSchema.validate(account).then(console.log);
// "name"
accountSchema.validateAt('name', account).catch(console.log);
// undefined

Am I doing something wrong?
(I hope not to parse path... but let me know )

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

No branches or pull requests

1 participant