You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
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
While
sendAPIRequest
is pending and former test pass, previous result of former one is not reflected.
const formerTest = string().matches(/123/, 'error 1')
return object().shape({
A: formerTest.test('latterTest', 'error 2', async (value) => {
if (await formerTest.isValid(value)) {
return await sendAPIRequest(value)
}),
// example
// input 12 -> show 'error 1' -> input 123 ->
// still show 'error 1'(I think it's not should come out) and promise is pending state ->
// promise resolved, disaapear 'error 1' and show (or not) 'error 2'
How to show
formerTest
's result regardless of promise status?
I'm not sure I understand what you are trying to accomplish.
Would something like this suffice?
const schema = yup.string().matches(/123/, 'error 1')
const res = await schema.validate('your input here')
await sendAPIRequest(res)
Or are you trying to get all the error messages first? If that's case you need to set
abortEarly
to
false
:
const schema = yup.string().matches(/123/, 'error 1').matches(/321/, 'error 2')
schema
.validate('your input', { abortEarly: false })
.then(res => console.log(`success: ${res}`))
.catch(e => console.log(`error: ${e.errors}`)) // => error 1, error 2