score:48

Accepted answer

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....

https://airbnb.io/enzyme/docs/api/ReactWrapper/props.html


Related Query

More Query from same tag