Hossam Mourad

How to run multiple variations of the same test

May 05, 2020

In some specs that we write daily, we want to have the ability to write multiple variations of the same test. For example if we have a function that adds two numbers together, you would want to try multiple variations for that function’s spec to truly test each case you could think of. For example you would like to add two positive numbers, two negative number, or one positive and one negative number.

You can do that by duplicating the spec multiple times and each time you assert different values. The other neat solution is to use jest.each or jest-in-case

👨‍💻 If you think there is a mistake in this post or you want to discuss, you can follow me on Twitter or send me an email. Have a nice day!

Written by Hossam Mourad.
A software developer specializing in front-end development with a passion for software development as a craftsmanship not only writing working code.
Resume / Email / LinkedIn / GitHub / Twitter