score:0
you are trying to render your component in isolation, which means you don't have access to the useparams
object. i'm not sure how to do this with enzyme, but here is how it works with testing library, which i believe should work with enzyme also.
try to wrap your component in your test suit with a router and pass the history object as a prop:
import {creatememoryhistory} from 'history'
const browsewithrouter = () => {
const history = creatememoryhistory();
return (
<router history={history}>
<browse />
</router>
)
};
then shallow render your new component:
const component = shallow(<browsewithrouter />)
Source: stackoverflow.com
Related Query
- Getting Jest error TypeError: Cannot read properties of undefined (reading 'match') when using useParams in the component?
- Getting constant error of - Uncaught TypeError: Cannot read properties of undefined (reading 'map')
- Getting an error of Cannot read properties of undefined (reading 'handleSubmit') in my console
- I am getting this error TypeError: Cannot read properties of undefined (reading 'header') , I am trying to middleware to get users data
- Jest:- TypeError: Cannot read properties of undefined (reading 'params'). Error coming in jest
- Im getting the error message Cannot read properties of undefined (reading 'product') in React
- Getting error when trying to pull data from firebase collection REACT: TypeError: Cannot read properties of undefined (reading 'map')
- Getting cannot read properties of undefined error when trying to map through prop generated by getStaticProps function
- React Router: TypeError Cannot read properties of undefined (reading 'originalPositionFor')
- Getting error Cannot read property 'setState' of undefined
- Jest - Test gives an error TypeError: Cannot read property 'then' of undefined
- Runtime error appeared after updating to webpack 5. TypeError: Cannot read properties of undefined (reading 'default')
- 'Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'writeFile')' error while trying to write to a file with REACT
- Cannot read properties of undefined (reading 'params') Uncaught TypeError whilte fetching data from JSON
- React, useRef not allowing to access current properties, getting Uncaught TypeError: Cannot read properties of undefined (reading 'clientHeight')
- React, getting Uncaught TypeError: Cannot read properties of undefined (reading 'map') on some refreshes
- Jest error '' TypeError: Cannot read property 'preventDefault' of undefined "
- Getting error TypeError: Cannot read property 'id' of undefined using React/Redux action
- Jest TypeError: Cannot read properties of undefined (reading 'html') at new JSDOMEnvironment
- Getting TypeError: Cannot read property 'map' of undefined error
- Cannot read properties of undefined error when working with an API in React
- Server Error TypeError: Cannot read properties of undefined (reading 'apps')
- React, not able to consume value inside context, getting Uncaught TypeError: Cannot read properties of undefined
- React - cannot read properties of undefined error showing up in a label
- I'm getting a Cannot read property of 'exercises' of undefined error when trying to map my props
- I'm attempting to call a function from the context in the componentDidMount function but i'm getting a Cannot read property of undefined error
- Cannot read properties of undefined (reading 'find') in Jest and Enzyme React 17
- Apparently no causes for the error "TypeError: Cannot read properties of undefined "
- Getting Cannot read properties of undefined (reading 'map')?
- I'm getting an "Uncaught TypeError: Cannot read properties of undefined (reading 'push')" with react-router-dom v6
More Query from same tag
- Reduce not removing correct array item
- Expand clickable region of thin div
- How to add conditional styles in emotion/react?
- undefined tag into preact component
- How can we upload multiple files using React.JS ? When we click on the upload button all the names of the selected files must appear
- How to get a value from code mirror in react js?
- Redux: drop part of state as unmounting component?
- How to avoid dragging the parent when dragging it's child?
- Global Functions in ReactJS tells me 'not a function'
- React Material-UI:I want the Accordion to popup on button click
- React, get bound parent dom element name within component
- pass value of object created when document loads into a variable in react
- it must be a function, usually from React.PropTypes
- react dynamically build href file URL using map() method
- How to subscribe to a Redux action in a React component
- How do I sort specific questions to a specific section?
- Error: Compiling RuleSet failed: Query arguments on 'loader' has been removed in favor of the 'options' property
- Why after x number of times Math.random() function gives only one number over and over
- Add Icons to project Material Table error
- fetch should not be in the action || reducer?
- How to handle "centering" your website in react
- testing react component, mocking props
- How to catch axios api call error 401 in reactjs?
- clock with setInterval not updating time
- How to pass onClick event to parent component when using iteration in ReactJS?
- How to call an API every 5 minutes using React?
- React : Apply Body overflow on specific component
- Disable submit button until the answer from the server is received in react-final-form
- CSSTransition to make a slide out drawer in css grid layout
- React native es5 vs es6 explanation request