DEV Community

Discussion on: Formik & React Testing Library and Screaming at a Computer for an Hour

Collapse
 
rangeoshun profile image
Abel Varga

Yeah, this will give you a false positive.

Collapse
 
charliewilco profile image
charlie⚡

how so?

Collapse
 
rangeoshun profile image
Abel Varga

In my case, I needed not just await the expect, but the problem also was the Formik did not call the handleSubmit callback. I had to fire a submit event on the form element itself.

Thread Thread
 
xap5xap profile image
XAVIER PEREZ

Hello. How do you submit an event on the form in the test?

Thread Thread
 
rangeoshun profile image
Abel Varga • Edited

Basically like this:

fireEvent.submit(container.querySelector('form'))

container is the value returned in the object by the render method.

Collapse
 
rangeoshun profile image
Abel Varga

If you do not await the wait in an async function, the test is over before the expectation could be evaluated.