score:1

You can create a function that returns the result of arrError.indexOf(..) but !!!! It's not a good practice.

First of all you should not test methods and functions that are from other frameworks and libraries and that you don't code yourself. If you want to test anything you should test every lifecycle method of React, every single method of Math, Array, etc.

Second, the key it's better to not be just an index and the use of indexOf is not necessary.

First approach, not the best, you can do directly:

{arrError.map((error, index) => (<div key = {index}>{error}</div>))}

Second approach, you don't have to use just the index for key (read this):

{arrError.map((error, index) => (<div key = {error.id}>{error.value}</div>))}

Each object in the array should have a unique property to use as key (you can even use a string. If error is a string and it's unique in the array you can just use error as key).


Related Query

More Query from same tag