To loop through dynamic test cases with Jest and JavaScript, we use the each
method.
For instance, we write
test.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])(".add(%i, %i)", (a, b, expected) => {
expect(a + b).toBe(expected);
});
to call test.each
with an array of arguments for the callback.
In the callback, we add the test code that uses the parameters.