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
I have a custom made component in my React app, that I would like to unit test.
The component that I would like to test consist of a custom text input component and a custom select component, containing a react-select component. The text input field is only showed to the user, if the user selects option "b" in the react-select component.
Which means the logic in the parent component is basically something like this:
select option = ["a", "b"]
if selectedOption === "b" display text input field
My problem is I cannot find any documentation on how to 1) add a data-testid to the react-select inside my CustomSelectComponnet and 2) How to mock a user event in my unit test that selects options "b", in order for me to test if the input field is to be found in the document.
This discussion was converted from issue #5348 on October 19, 2022 05:22.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a custom made component in my React app, that I would like to unit test.
The component that I would like to test consist of a custom text input component and a custom select component, containing a react-select component. The text input field is only showed to the user, if the user selects option "b" in the react-select component.
Which means the logic in the parent component is basically something like this:
select option = ["a", "b"]
if selectedOption === "b" display text input field
Parent component:
Custom select component containing react-select:
My problem is I cannot find any documentation on how to 1) add a data-testid to the react-select inside my CustomSelectComponnet and 2) How to mock a user event in my unit test that selects options "b", in order for me to test if the input field is to be found in the document.
Any help?
Beta Was this translation helpful? Give feedback.
All reactions