subComponentWith

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

This combinator allows you to make an assertion that applies to at least one sub-component directly spun up by the component under test.

Note that this combinator only works on direct child-components, i.e. sub-components not further than one level deep.

If you want to make assertions over deeply nested sub-components, check out deepSubComponentWith.

Example Use

Suppose you've got a MyComponentSpec which takes a text prop and creates multiple children; one of them a com.facebook.litho.widget.Text with a truncated version of your text. You want to verify that there is a direct child present that contains the text that you have passed in:

mComponent = MyComponent.create(c).text("Cells interlinked within cells interlinked").build();
assertThat(c, mComponent)
  .has(subComponentWith(c, textEquals("Cells interlink...")))
  .doesNotHave(subComponentWith(c, text(containsString("within cells"))));
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.

See also