Summary
Add new features behind flags to increase compatibility with React Enzyme adapters
What's Changed
-
Adds a new shallow renderer that more closely matches the behavior of the React 16 shallow renderer. This new renderer can be enabled by importing
CompatShallowRenderer
fromenzyme-adapter-preact-pure/compat
and passing it in theShallowRenderer
Adapter option.The previous shallow renderer rendered components into a DOM and modified the component's output so that all children return null to prevent rendering further down the tree. The compat shallow renderer is a custom implementation of Preact's diffing algorithm that only shallow renders the given component and does not recurse down the VDOM tree. It's behavior more closely matches the React 16 Enzyme adapter and it well suited for migrating an Enzyme test suite from React to Preact.
-
Support more return types (e.g. booleans, numbers, BigInts) from components
-
Add an option (
renderToString
) to allow passing in a custom string renderer to use for Enzyme's 'string' renderer instead of rendering into the DOM and reading the HTML output. It is expected thatrenderToString
frompreact-render-to-string
is passed into this option. This change enables using the string renderer in non-DOM environments and more closely matches the React adapter's behavior. -
Add a feature flag (
simulateEventsOnComponents
) for supporting simulating events on Components #211This new feature flag turns on behavior that enables calling
.simulate
directly on Components. For shallow rendering, this directly calls the component's corresponding prop. For mount rendering, it finds the first DOM node in the Component, and dispatches the event from it.NOTE: This flag changes the behavior of calling
simulate
on shallow rendered host (a.k.a DOM) nodes. When this flag is off,simulate
dispatches a native DOM event on the host node. When this flag is turned on,simulate
directly calls the prop of the event handler with arguments passed tosimulate
.The behavior turned on by this flag matches the behavior of the React 16 Enzyme adapter.
Pull Requests
(bump dependency PRs not included)
- Change various "Preact 10" references to Preact by @robertknight in #178
- Fix TypeScript example by @robertknight in #199
- Build and run examples in CI by @robertknight in #200
- Consistently use
import type
by @andrewiggins in #209 - Add husky and lint-staged flow for formatting by @andrewiggins in #212
- Upgrade workflow actions by @andrewiggins in #210
- Use yarn to run lint-staged by @andrewiggins in #216
- Add support for simulating events on Components by @andrewiggins in #211
- Add linting by @andrewiggins in #218
- Add option to use
preact-render-to-string
for the StringRenderer by @andrewiggins in #222 - Support more component return types by @andrewiggins in #221
- Add custom Preact shallow diff algorithm by @andrewiggins in #223
- Moved integration shared tests into the shared test utils file by @andrewiggins in #232
- docs: Correct the directories listed in examples' readmes by @rschristian in #235
- Integrate new compat shallow renderer into Enzyme by @andrewiggins in #233
- Add example that uses the compat renderer by @andrewiggins in #236
- Document new options in Readme by @andrewiggins in #240
- Prepare changelog for release by @andrewiggins in #241
New Contributors
- @rschristian made their first contribution in #235
Full Changelog: v4.0.1...v4.1.0