Checkout the getting started section to setup the test environment correctly.
@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
@RunWith(LithoTestRunner.class)to the top of the test class.
- Add a JUnit
- Add a check to ensure that tests are run in debug mode.
ComponentsConfiguration.IS_INTERNAL_BUILDmust 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.
Kettle object is instantiated with a temperature, that is verified using a custom matcher.
Components can also be
@InjectProps. Consider the following LayoutSpec:
- Assert if MyInjectProp is mounted with the injected Text component.