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:

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

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

{, index) => (<div key = {}>{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