Unit Testing Sections
SectionComponentTestHelper provides helper functions to easily test the output of GroupSectionSpecs and state updates.
To demonstrate the testing functionality, consider this simple group section with a a list of text and an optional image header.
Testing Children
SectionComponentTestHelper
helps you test a group section spec's @OnCreateChildren
method by returning
the children of a section as a list of SubSection. SubSections can either be matched by exact props or by section class. These are best used as existence checks.
Testing State
Sometimes your section's behavior is based on both external props and internal state. You can change state variables and test new behavior by performing state updates on the scoped context.
Testing events
Sections heavily uses the event handling system and SectionComponentTestHelper
has helper methods to make testing events easier. Simply create an event handler using the scoped context and dispatch your event to execute the event handler.
Testing other lifecycle methods
Testing other lifecycle methods is as simple as calling the lifecycle method with the section under test and it's corresponding scoped context.
See VerySimpleGroupSectionSpecTest for the full source of this example! Testing for sections is still very basic so if you run into any missing functionality please reach out to us and describe your use case.