DEV Community

Discussion on: Simplify repetitive Jest test cases with test.each

Collapse
 
ekhro97 profile image
Joel Coll

What is the benefit of using the test.each of jest instead of js for each? I think it is more readable and friendly the js way

Collapse
 
mpeloquin profile image
Maxime Péloquin

Using test.each will create one test for each test case, so if it fails, you will know exactly which test case failed. It will also run the rest of the test cases even if one failed.

If you use for each, then your entire test will fail on the first case failure, and you will not know which one failed quickly.

Collapse
 
usersaurus profile image
Antonio Luis Román

That's not completely true. You can put an it inside a forEach loop and get the same behavior.