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.Dismiss alert
馃悰 Not able to test the error state of the form using Formik, Yup and Enzyme
TLDR: code sandbox provided, see below.
I've seen some issues vaguely similar but they seem to be outdated and a few potentially useful links are broken.
Current Behavior
Given my simple form built with Formik and Yup, I'm trying to test with Jest/Enzyme the scenario where I:
type a wrong email
press tab (blur)
check that the error is displyed and the new email value is displayed
Expected behavior
At a high level: after the events above I expect the form to receive the expected errors (i.e. errors.email) so that it triggers the rendering of my error msg. (this works in the browser)
In the unit tests: after I run a myfield.simulate('change', {target: ..etc}'); myfield.blur() I should be able to test that the error message has appeared and the email value is displayed.
Reproducible example
It works on a browser but it doesn't seem to work in the unit tests, using Enzyme. (Or maybe I'm just doing it wrong).
The text was updated successfully, but these errors were encountered:
giulioambrogi
changed the title
Formik + Yup onChange and onBlur events not working with Enzyme
Formik + Yup can't test form errors with Enzyme
Nov 30, 2018
Hi @cagmz thanks, how about the other test? That was the key problem actually, maybe I'll open a separate ticket for that.
@jaredpalmer I has asked two questions (see 2 broken tests in the code sandbox) so I don't think this should be closed as @cagmz answered only 1 of them.
I solved this by manually calling ui.update() after a tick. It looks like the issue is with how formik validates asynchronously. See passing tests here: https://codesandbox.io/s/y2vqqwr0yv
馃悰 Not able to test the error state of the form using Formik, Yup and Enzyme
TLDR: code sandbox provided, see below.
I've seen some issues vaguely similar but they seem to be outdated and a few potentially useful links are broken.
Current Behavior
Given my simple form built with Formik and Yup, I'm trying to test with Jest/Enzyme the scenario where I:
Expected behavior
At a high level: after the events above I expect the form to receive the expected errors (i.e.
errors.email
) so that it triggers the rendering of my error msg. (this works in the browser)In the unit tests: after I run a
myfield.simulate('change', {target: ..etc}'); myfield.blur()
I should be able to test that the error message has appeared and the email value is displayed.Reproducible example
It works on a browser but it doesn't seem to work in the unit tests, using Enzyme. (Or maybe I'm just doing it wrong).
Please have a look at the 2 tests in this Code Sandbox demo
Environment
The text was updated successfully, but these errors were encountered: