deepSubComponentWith

open fun deepSubComponentWith(c: ComponentContext, inner: Condition<InspectableComponent>): Condition<in Component>

Verify that a component tree contains a component that matches the provided condition at any level in its tree.

Note that asserting on indirect children breaks encapsulation and can lead to Change Detector Tests[0]. Prefer subComponentWith over this whenever possible.

Example Use

Suppose you have a MyWrapperComponentSpec that creates a which contains a com.facebook.litho.widget.Text for a text prop that your component accepts.

You want to ensure that the text truncation logic correctly applies to the text that sits inside the card. Using subComponentWith won't work here as it will only be able to make assertions on the but not the com.facebook.litho.widget.Text sitting inside.


mComponent = MyWrapperComponent.create(c).text("I'm Mr. Meeseeks! Look at me!").build();
assertThat(c, mComponent)
  .has(deepSubComponentWith(c, textEquals("I'm Mr. Meeseeks!")))
  .doesNotHave(deepSubComponentWith(c, text(containsString("wubba lubba dub dub"))));
For more applicable combinators, see below:

Parameters

c

The ComponentContext used to create the tree.

inner

The condition that at least one sub component needs to match.

[0] https://testing.googleblog.com/2015/01/testing-on-toilet-change-detector-tests.html

See also