Skip to content

v4.1.0

Latest
Compare
Choose a tag to compare
@andrewiggins andrewiggins released this 05 Jan 19:57
· 7 commits to master since this release

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 from enzyme-adapter-preact-pure/compat and passing it in the ShallowRenderer 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 that renderToString from preact-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 #211

    This 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 to simulate.

    The behavior turned on by this flag matches the behavior of the React 16 Enzyme adapter.

Pull Requests

(bump dependency PRs not included)

New Contributors

Full Changelog: v4.0.1...v4.1.0