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).
Source: stackoverflow.com
Related Query
- How to write test case coverage in Jest and Enzyme for indexOf used inside React Component
- How to write a test case for a simple React component using Jest and Enzyme
- How to write test case for ErrorBoundary in React using Jest / Enzyme
- How to write test case by using jest for Increment using React Hooks
- How to write test cases for a function using jest and enzyme
- How to test the style inside the CSS class for React component using Jest and Enzyme?
- How to write test cases in enzyme and jest for a component using useDropZone?
- write unit test for event handlers that updates some state in react using jest and enzyme
- how to test react-context using jest and enzyme where context is used inside constructor?
- How to write test case using Jest for Yup.isValid function?
- How to check the value of a nested React component in a unit test with Enzyme and Jest
- How to test functions in React with Jest and Enzyme
- How to test styles and media queries rendered by a React component with Jest and/or Enzyme
- how to test OnSubmit in React using Jest and Enzyme
- How to test onChange for ui-material TextField using Jest and Enzyme
- How to write Test cases for useEffect Hook in React using Jest & Enzyme?
- How to write test case for url push in useEffect react hook?
- How can I test if child React component was rendered based on a URL change using Jest and Enzyme
- How to test async handleSubmit(e) in react with jest and enzyme
- How do I write state case for the state in react useState using Jest
- How to write unit test case for componentDidMount() and export default connect(null, updateProps)(<ComponentName>) with JEST/Enzyme in React?
- How should I write Jest Test cases for styled component and spy on css to verify if the styles?
- How to test if a prop is rendered correctly in a Component using Jest and Enzyme in React
- How to test if state of a component is changed by the function using jest and Enzyme in React TDD
- How to write a test with Jest and React testing library to check if anchor-tag <a /> exist
- How to write a Jest-enzyme test case for code in React useEffect whose dependencies are updated in its child component
- How to test React with hooks and PubSub-js with Jest Enzyme
- How to write test case for a component which is calling a method using jest
- How to cover test cases for Svg react component using Jest + Enzyme
- How do you test for the non-existence of an element using jest and react-testing-library?
More Query from same tag
- ReactJs: transitions in nested elements
- React Router Declared but doesn't work please
- My app crashes when I use for or while loops
- What is shallow rendering in Jest unit tests in React?
- this.handleClick vs this.handleClick()
- React / Neovis.js: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS
- How do I return an input tag from a function?
- How to make a shadow on Semantic Ui React Navbar Menu
- One route works and one doesn't
- mapping objects inside another mapping react native
- Array state is disappeared when array mapping
- How to Filter multi-select values in nested array of objects
- React Material UI delayed permission dialog
- How can i use Jest to test a function inside a stateless component?
- 500 server error when submitting email with SendGrid + NextJS
- "Type Error : is not a function" in a Jest test
- Adding Id attribute to multiple checkboxes
- What is the correct way to pass through generics in this instance?
- how to remove picture from data using api in react
- React-Redux UI bug. Lag in Image update
- React map function works, but when API called it breaks
- How do I generate dynamic meta description and image in React using React Helmet?
- Debugging Redux / React with Webpack
- How to change input with a given value?
- Uncaught (in promise) DOMException: Document.querySelector with Google Fonts Link in NextJS
- how can I create a component where I can add as many levels of subpoints I can recursively in a react component
- React testing - How can I mock or inject data in the store to be provided as props to component
- How to send API requests to a server via JSON? Keep getting CORS errors
- Is there a way that we can trigger mouseover event on echarts library when hovering on any point of the series, rather than hover on a data point?
- React -Redux: Why is data not ready even if fetching is finished?