Matching @InjectProp
note
Checkout the getting started section to setup the test environment correctly.
tip
Checkout the sub-component testing, and Prop Matching
section before diving into @InjectProp
testing.
#
Testing injected props@InjectProp
earmarks props to be provided by the client's dependency injection framework.
Components which have injected props can be tested using a @TestSpec
and the prop-matching APIs.
Consider the following LayoutSpec:
- Create a
@TestSpec
for MyInjectPropSpec
- Add
@RunWith(LithoTestRunner.class)
to the top of the test class. - Add a JUnit
@Rule
LithoViewRule
. - Add a check to ensure that tests are run in debug mode.
ComponentsConfiguration.IS_INTERNAL_BUILD
must be true.
The test class should look like the following:
- Set the value of the injected props before evaluating any assertions.
The example shows how tests written for injected props are almost the same as normal props.
The Kettle
object is instantiated with a temperature, that is verified using a custom matcher.
#
Testing injected componentsComponents can also be @InjectProp
s. Consider the following LayoutSpec:
- Assert if MyInjectProp is mounted with the injected Text component.