to render as
- <PreactElement> to [exactly] [deeply] render [with all children] [with all wrappers] [with all classes] [with all attributes] as <PreactElement>
Given the following test component:
You can validate the rendering of this component with the to render as
assertion,
which renders the component to a new DOM node, and validates the output.
You can optionally use 'to deeply render as'
, which for Preact is identical, but does mean that the assertions will be compatible with unexpected-react.
If you want the ability to switch to React and keep the same tests, it is advisable to use 'to deeply render as'
.
This works using the same rules as to have rendered
, but saves you creating a
new DOM node when you just want to validate some translation of props to
output.
If you want to check for an exact render, use 'to exactly render as'
.
Alternatively, if you don't care about extra props, but want to check that there are no extra child nodes, use 'to have rendered with all children'
Note that exactly
implies with all children
, so you using both options is not necessary.
Normally wrappers (elements that simply wrap other components) are ignored. This can be useful if you have higher order
components wrapping your components, you can simply ignore them in your tests (they will be shown greyed out
if there is a "real" error). If you want to test that there are no extra wrappers, simply add
with all wrappers
to the assertion.
If you want to trigger events, use the when rendered
assertion to render
the component, then use the other with event
and to have rendered
or to contain
assertions to validate the output.