score:48
After some digging, I found the following. The indicated line in the question:
const src = img.node.props.src;
can be simplified to the following:
const src = img.prop('src');
The documentation can be found here.
If someone knows of a non-Enzyme way of doing this, I'd still be interested in hearing about it.
score:1
.node is not working After some hard work, I found the following is 100% related to answer for above question
const src = img.getElement().props.src;
score:10
For me this worked
expect(component.find('button').props().disabled).toBeTruthy();
score:10
The @testing-library/jest-dom library provides a custom matcher toHaveAttribute
. After extending expect
clause
import '@testing-library/jest-dom/extend-expect'
we can assert like
const rect = document.querySelector('[data-testid="my-rect"]')
expect(rect).toHaveAttribute('width', '256')
score:12
With React Test Utilities:
it('should have the logo image', () =>
const app = TestUtils.renderIntoDocument(<App/>);
var image = TestUtils.findRenderedDOMComponentWithTag(app, 'img');
expect(image.getDOMNode().getAttribute('src')).toEqual('logo.svg');
});
Enzyme tests looks much cleaner.
score:17
For me, it worked as below
expect(companySelect.find('input').props()["disabled"]).toBe(true)
props()
returns an object having all the attributes of the selector and then it can be browsed as an object.
Hope this helps too....
Source: stackoverflow.com
Related Query
- How do I get an attribute of an element nested in a React component using Jest and/or Enzyme?
- How to get the react component instance corresponding to event.target element in a click handler?
- How to get width of element using React ref?
- How to get a React Component reference to change its class using classList?
- How to get the element with the testid using react testing library?
- How to test below component in React using JEST
- Using React how do I toggle the visibility of a nested component from a container component?
- How can I get d3 in a React component to render in a Jest snapshot
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How to check the value of a nested React component in a unit test with Enzyme and Jest
- How to get the value of the span element with testid using react testing library?
- How to get accumulated price in a nested array using reduce in React
- How to mock async call in React functional component using jest
- How to mock properly with Jest a React component using render props
- How to access previous index route in nested routes using Link component from react router?
- How to mock imported React higher order component using jest & enzyme?
- How to get data from table row click using Semantic's React Table Component
- How to extract nested type of an attribute passed as props to a React function component
- How to test react functional component correctly using jest and enzyme?
- How to pass data from blade.php file to a react component using HTML element attributes?
- How to get http header(LDAP user attribute set by Nginx) with React component
- How to get nested Object from JSON File using React JS
- How to get an element height in react js with out using any pulgin
- How to access data from get request made by a React functional component to localhost server using Axios?
- How does this functional component using react hooks get its parameters?
- How can I test if child React component was rendered based on a URL change using Jest and Enzyme
- How to get parent props in child component when using styled component in react
- How to get Component by dynamic testid using React Testing Library
- How to get text element of the given react component in React.cloneElement?
- I'm using react-slick, how can I export a React Component as a single element but remove the parent div on render
More Query from same tag
- React query mutation: getting the response from the server with onError callback when the API call fails
- How do I get a count of this API data?
- React Tutorial: TypeError: Cannot read property 'props' of undefined
- What is the correct way to type a React HOC?
- ReactJS: Help debugging? Sum of each array NOT columns
- React named class component vs anonymous class component
- How to handle events with onClick in ReactJS
- Material UI pagination how to change color
- React configureStore2.default.firestore is not a function
- TypeError: Cannot read property 'filter' of undefined. Any suggestion?
- change data from array state reactjs
- React Dynamically add n divs to the page on button click
- connected-react-router app updates url but not components
- Jest mock module resolve with variable value
- How to access stateless component state inside window event listener?
- React-Bootstrap - importing modules
- Getting Property map doest not exist on Array
- Obtaining Selected Value in React-Select
- React AgGrid - Row Style based on conditions from the props
- React map, props undefined
- How to call whole array in API call
- Highlight current page in bootstrap with react
- How to format DateTime in DateFNS when using another format to show the Date?
- Update an antd RangePicker from outside the component
- React state - what I am doing wrong?
- how to better format data pulled from api onto a ant design table
- How to use Private Route using react-router?
- Using useEffect for listening to state changes
- How to find focused React component? (like document.activeElement)
- Div triangle not displaying