title: How do I get an attribute of an element nested in a React component using Jest and/or Enzyme?
body: <p>I want to test to see whether an image has properly loaded in a React app. I have decided to check the <code>src</code> attribute of the <code>img</code> element nested within the React component. I want to use the Jest testing framework and, if needed, the Enzyme testing utility.</p>
  
  <p>By digging through the <code>Object.keys</code> of a shallow React test component, I was able to come up with the following solution. The line I'm uncertain about is indicated with the asterisks.</p>
  
  <pre><code>import React     from 'react';
  import {shallow} from 'enzyme';
  import App       from './App';
  
  it('should have the logo image', () =&gt; {
    const app = shallow(&lt;App /&gt;);
    const img = app.find('img');
    const src = img.node.props.src; // ******
    expect(src).toBe('logo.svg');
  });
  </code></pre>
  
  <p>This solution <em>does</em> work but it seems a little convoluted (it requires a property of a property of a property of a wrapper) and seems somewhat obscure (I can't easily find clear instructions for this online). So, is this the correct/simplest way to do this?</p>
  
  <ul>
  <li>If so, where is the documentation?</li>
  <li>If not, how else should/could I be doing this? e.g. Is there some ready-made <code>getAttribute</code> or <code>retrieveProp</code> method, etc. in Enzyme? Is there a better way of doing this using something else instead of Enzyme, e.g. <code>react-addons-test-utils</code>?</li>
  </ul>
  
  <p><a href="https://stackoverflow.com/q/29882520/5218951">This question</a> about React element attributes doesn't seem to quite answer it for me even though the poster there also indicates having a hard time finding documentation about asserting a rendered attribute value. A number of other questions (e.g. <a href="https://stackoverflow.com/q/40858984/5218951">here</a>, <a href="https://stackoverflow.com/q/39854162/5218951">here</a> and <a href="https://stackoverflow.com/q/40466134/5218951">here</a>) deal with React/Jest/Enzyme but don't deal with retrieving attribute values.</p>