UNPKG

enzyme-adapter-preact-pure

Version:

Enzyme adapter for Preact

59 lines (58 loc) 3.09 kB
import type { AdapterOptions, MountRendererProps, RSTNode, RSTNodeChild, ShallowRendererProps, ShallowRenderer as AbstractShallowRenderer } from 'enzyme'; import enzyme from 'enzyme'; import type { ReactElement } from 'react'; import type { VNode } from 'preact'; import MountRenderer from './MountRenderer.js'; import ShallowRenderer from './ShallowRenderer.js'; import RootFinder from './RootFinder.js'; export declare const EnzymeAdapter: typeof enzyme.EnzymeAdapter; export interface PreactAdapterOptions { /** * Turn 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. This behavior matches the behavior of the * React 16 Enzyme adapter. */ simulateEventsOnComponents?: boolean; /** * An option to provide a custom string renderer for Enzyme's `string` rendering mode * instead of mounting into a DOM and extracting the markup. It is expected * that preact-render-to-string is passed here. */ renderToString?: (el: VNode<any>, context: any) => string; /** * An option to provide a custom ShallowRenderer implementation. * * This option is primarily used to provide 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 * it's output so that all children return null to prevent rendering further * down the tree. The new 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. */ ShallowRenderer?: { new (options: PreactAdapterOptions): AbstractShallowRenderer; }; } export default class Adapter extends EnzymeAdapter { private preactAdapterOptions; constructor(preactAdapterOptions?: PreactAdapterOptions); createRenderer(options: AdapterOptions & MountRendererProps): AbstractShallowRenderer | ShallowRenderer | MountRenderer; nodeToElement(node: RSTNodeChild): ReactElement | string; nodeToHostNode(node: RSTNodeChild): Node | null; isValidElement(el: any): boolean; createElement(type: string | Function, props: Object | null, ...children: ReactElement[]): ReactElement; elementToNode(el: ReactElement): RSTNode; wrapWithWrappingComponent: (el: ReactElement, options?: ShallowRendererProps) => { RootFinder: typeof RootFinder; node: ReactElement<any, string | import("react").JSXElementConstructor<any>>; }; }