Skip to main content

Matching @TreeProp


Checkout the getting started section to setup the test environment correctly.


Checkout the sub-component testing section before diving into @TreeProp testing.

Testing components with @TreeProp#

While @Prop are received from the immediate parent, @TreeProp can be passed down to a component from any of its ancestors in the current component hierarchy. When testing hierarchies containing components which contain @TreeProp, tree props should be be passed down to the components as expected.

class ComponentWithTreePropSpec {
static Component onCreateLayout(
ComponentContext c,
@Prop String normalProp,
@TreeProp UserContext userContext) { // <- Should be passed down by ancestors.
// ...

Use LithoViewRule#setTreeProp(Class, Object) to set a @TreeProp.

public class ComponentWithTreePropTest {
public final @Rule LithoViewRule mLithoViewRule = new LithoViewRule();
public void test() {
final ComponentContext c = mLithoViewRule.getContext();
final Component component = ComponentWithTreeProp.create(c).build();
.setTreeProp(UserContext.class, new UserContext()) // setting tree props for the hierarchy.
// test assertions as usual

@TestSpec does not support matching @TreeProp.