Closed panchal-krunal closed 2 years ago
I'd suggest avoiding simulate - it doesn't reliably simulate anything.
These are the tests you need:
onClick
, that when explicitly invoked with .invoke()
, does what you expect.You do not need to be testing React or the browser itself - just your component, and the resulting onClick props.
Hi @ljharb can you please give me an example of how to test my component?
I tried the same thing, on button click and checking what is expected, can you please how to achieve it?
You have wrapper
- so you'd have 3 assertions, one for each of the form controls; and then you'd have invoke each form control's onClick
and assert on the effects of doing so.
I'm sorry, but I can't write your tests for you.
Thanks @ljharb will try
@panchal-krunal did you write the tests. If yes pls post them I cannot understand how to write them.
Please provide the example test code to understand about mocking multiple usestate
Hi All, I am having a login component with two input boxes and one button. I am trying to simulate button click and validate my input boxes in my functional react component. Below is my code -
I am trying to simulate button click and test the validation inside onSubmitButtonClick
I am able to run the test, but it is failing, I debugged and found that the last value set in mocking state in testcase is getting set for username and password, how can I set different value for all useState ?