testing formik in jest #333
Replies: 3 comments 3 replies
-
Hi @StefanZivkovic. Your starting comment here is pretty vague. Could you provide a generic example of a small view using formik and/or what the specific difficulties are? A codesandbox showcasing the issues would go a long way in others being able to help. |
Beta Was this translation helpful? Give feedback.
-
The line What you probably want to use is You also want to make sure that the label is correctly associated to the form input field. |
Beta Was this translation helpful? Give feedback.
-
You should try to debug what these find/get/query helpers are giving you at each step of the way, and determine what's wrong. In this case I'd say the error message is already really helpful and you gotta do the rest of the work on top of what's telling you, in order to figure it out in the specific situation of your project and code. There debugging helpers and patterns in react testing library. In general I'd recommend you to checkout the testing library website where all these things are documented, there are examples, etc. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am not sure if this is the right place or is it the formik github, but i have issues to test formik. Do i have to mock something regarding
formik
in my tests before testing them?EDIT: Sorry for this long feedback from my side. This is the basic sandbox https://codesandbox.io/s/mo4fi?file=/src/App.js. Usually i would like to test validation messages - how they change based on input. But i have issues here to perform simple
fireEvent.change()
command with given error:And later i can't find out how to grab that validation message. I try with await wait + getByText, and i try also without await wait but with findByText, but without success.
Beta Was this translation helpful? Give feedback.
All reactions