enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.96k stars 2.01k forks source link

How to test the form which is rendered based on props in class component in react.js ? #2568

Closed yogendrakumar96 closed 1 year ago

yogendrakumar96 commented 1 year ago

Here I want to test the form if create ticket is there then I should render the form otherwise I want to render the error. How to test it any idea about this ?

{ 
createTicket != undefined ? <div className="container">
<form onSubmit={this.onSubmit} id="ticket-form"><DynamicFormField /></form></div> : <ErrorUI/>
}
ljharb commented 1 year ago

I'm not sure what you're asking.

If you have a prop (createTicket) whose value influences which components are rendered, you'd do multiple shallow tests, one for each variation of createTicket, and assert on what things are rendered in each case.

yogendrakumar96 commented 1 year ago

I'm not sure what you're asking.

If you have a prop (createTicket) whose value influences which components are rendered, you'd do multiple shallow tests, one for each variation of createTicket, and assert on what things are rendered in each case.

I want to test this form rendering based create ticket props. If the create ticket props is there then I want to render the component. How to do this ? can you please tell me ?

ljharb commented 1 year ago

It sounds like you’re just asking how to write tests in general - I’d suggest StackOverflow, IRC, or Slack for that, as i can’t offer that service here.