user1894292
user1894292

Reputation: 859

Test Nested Tag attribute inside Parent Tag's attribute

I have a tag that is nested inside another tag's attribute.

Exhibit a.

<Tag
    input={(
      <NestedTag
        value={this.props.value}
        onChange={this.validate}
      />
    )}
  />

What I want to do is check that value inside NestedTag is correct.

In Enzyme, I've got as far as this:

expect(
  wrap
    .find(Tag)
    .at(0)
    .prop('input')
).toBe(...tag info goes here);

This is as far as I've gotten so far. I just don't know how to look inside "input" and poke around inside NestedTag.

I know I can use toMatchObject, but I've prefer to check each individual property in isolation.

Upvotes: 1

Views: 100

Answers (1)

Chris B.
Chris B.

Reputation: 5763

As per my comment, if Tag is rendering its input prop as a child, you can simply find it provided that the component is mounted first.

Cheers!

Upvotes: 1

Related Questions