When submitting the form in unit tests, the data validation is performed asynchronously. Therefore, in tests the flow of execution (after submit, checking conditions) continues without awaiting for the validation to complete, after which the onSubmit mock callback is invoked. The result of the test can therefore vary depending on the performance of the machine they are run on (on my machine, for example, this was not evident because the validation completed before the condition was checked).
This is fixed by using the waitFor function as documented here.
When submitting the form in unit tests, the data validation is performed asynchronously. Therefore, in tests the flow of execution (after submit, checking conditions) continues without awaiting for the validation to complete, after which the
onSubmit
mock callback is invoked. The result of the test can therefore vary depending on the performance of the machine they are run on (on my machine, for example, this was not evident because the validation completed before the condition was checked).This is fixed by using the
waitFor
function as documented here.