mercredi 16 décembre 2020

How to assert for text in a nested element with enzyme Shallow?

I have a component which renders another component, I am creating it with shallow like this:

const component = shallow(<ABC {...props} />);

when I run component.html() - I can see this output

    <div class="abc">
      <div attribute1="hi" class="dynamically generated">
        First
      </div>
      <div attribute2="bye" class="dynamically generated">
        second
      </div>
    </div>

I'd like to write an assertion to check that the text "First" is there.

I've tried various combinations e.g. find(ABC2).find('[attribute1="hi"]') ABC2 is the component that is rendered inside ABC and it shows correctly in the html output but I can't seem to figure out how to assert the text.

Aucun commentaire:

Enregistrer un commentaire