public class SubComponentExtractor extends Object
org.assertj.core.api.Assertions#assertThat
.
In most cases you will want to use the #subComponentWith(ComponentContext, Condition)
combinator.
Modifier and Type | Method and Description |
---|---|
List<InspectableComponent> |
extract(Component input) |
static <any> |
numOfSubComponents(ComponentContext c,
<any> matcher)
This combinator allows you to make an assertion on the number of sub-components directly spun
up by the component under test.
|
static SubComponentExtractor |
subComponents(ComponentContext c) |
static <any> |
subComponentWith(ComponentContext c,
<any> inner)
This combinator allows you to make an assertion that applies to at least one sub-component
directly spun up by the component under test.
|
public List<InspectableComponent> extract(Component input)
public static SubComponentExtractor subComponents(ComponentContext c)
public static <any> subComponentWith(ComponentContext c, <any> inner)
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 SubComponentDeepExtractor#deepSubComponentWith(ComponentContext, Condition)
.
MyComponentSpec
which takes a text
prop and
creates multiple children; one of them a 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:c
- The ComponentContext used to create the tree.inner
- The condition that at least one sub component needs to match.org.hamcrest.CoreMatchers
,
ComponentConditions
public static <any> numOfSubComponents(ComponentContext c, <any> matcher)
c
- The ComponentContext used to create the tree.matcher
- The Matcher that verifies the number of sub-components against a condition