score:2
Accepted answer
The problem is that you're rendering once, in the describe
block. This probably doesn't work how you think. Code in describe
blocks that isn't inside a test
(or other jest function like beforeEach
) gets run ahead of time by Jest. In general you never want any code inside a describe
block but outside a test
(or other jest function).
You could either render the component in a beforeEach
or have a render helper function you call in each test.
I forked your sandbox here with the above approach and both tests now pass: https://codesandbox.io/s/v3wk1vlx3l
Source: stackoverflow.com
Related Query
- React Testing Library: Test if children are passed / rendered correctly
- how to output current rendered component in react testing library unit test
- How to test the value of the props of react component rendered using react testing library
- How to test condition rendered elements with react testing library
- Test onClick of a button is called when there is no props passed down to it using testing library react and jest
- react testing library assert dropdown options are rendered in correct order
- How to test conditionally rendered string using React testing library and jest
- How to test a className with the Jest and React testing library
- How to test material ui autocomplete with react testing library
- fireEvent.keyDown not working as expected on my Jest + React Testing Library test
- React context is undefined when the children are rendered using this.props.children
- How to test Material UI Select Component with React Testing Library
- React Testing Library (RTL): test a responsive design
- How to test components internal functions with React testing library
- How to test HTML content with React testing library
- Test input Search box with React testing library
- How to test Material-UI's Responsive UI (e.g. Hidden, Grid, Breakpoints) in React with Enzyme or React Testing Library
- Apollo useQuery() throws Error: ECONNREFUSED when running async test in React Testing Library
- How to test redux state update with react testing library and jest
- How to test `contenteditable` events with React Testing Library
- How to properly test React Native Modals using Jest and Native Testing Library
- How to test if React component is returning null or its children using React Testing Library?
- Unit test form submission with data using react testing library
- How to write test cases for tabs in material-ui using react testing library
- React callback to scroll after all children are rendered
- Having an issue while up and running unit test with react redux testing library
- React testing library - how to get all instances of rendered components?
- React Testing Library - Failing to test Window Resize React Hook
- React testing library + Jest: How to test a component that receives a number then format it
- how to test Routes in react using jest and react testing library
More Query from same tag
- React select with value null
- Reusing component with absolute position in a flexbox
- how to detect the bug of filter not working reactjs
- How to convert an Array to an Array of Objects in JS & React using "react-select"
- How to add event for dangerousSetHtml?
- How do I get a component to "listen" to changes in global state in a sibling component?
- Material-ui Hover
- Capturing grid item click event in react-grid-layout
- Unable to resolve "./aws-exports" from "App.js"
- Coordinates array from PolylineMeasure plugin (react leaflet)
- Reset Password in React
- How do I include embed code with an external script in the body of a Gatsby site?
- How to pass props within components with react-router v6
- How to properly access props inside a component
- Animate Presence exit not working framer motion
- Socketio implementation with FastApi and React
- How to link image upload to strapi entry creation
- Making a Higher Order Component to inter-operate react-relay and react-router with TypeScript
- ReactJS - JavaScript: How to zoom on customized marker after click on it
- Is there a way to resize grid boxes?
- ReactJS How to change an icon (SVG) onClick?
- Why useEffect doesn't run on window.location.pathname changes?
- TypeScript error - property component does not exist on React mui MenuItem
- Convert react dispatch arrow function to tyescript
- How can I mock with jest multiple different responses when I'm using custom react hooks?
- Is there a way to add a tooltip to the rating component on Material UI?
- Objects are not valid as a React child getting error when adding div?
- change active tab background color in react material-ui
- TypeError: undefined is not an object in React
- ReactJS: axios POST with recursive function