shallowly
Version:
Shallowly: Modern shallow renderer for React 18+. Enzyme-compatible API, 2x faster, with TypeScript support.
51 lines (50 loc) • 1.74 kB
TypeScript
/**
* Wrapper for shallow rendering of React components (Enzyme-like). Provides
* utilities to get text, props, find descendants without deep rendering and
* prevents hooks execution in child components.
*/
export class ShallowWrapper {
/**
* @param {React.ReactElement|Array<React.ReactNode>} component Root element.
* @param {boolean} [shouldRender=true] Whether to execute render.
*/
constructor(component: React.ReactElement | Array<React.ReactNode>, shouldRender?: boolean);
component: React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactNode[];
shouldRender: boolean;
renderedElement: React.ReactNode;
/**
* Performs a shallow render of the current element. If `shouldRender` is
* false, returns the original element without executing its body.
* @returns {React.ReactNode}
*/
render(): React.ReactNode;
text(): string;
/**
* Returns all props of the current element.
* @returns {Record<string, any>}
*/
props(): Record<string, any>;
/**
* Returns specific prop value.
* @param {string} key
* @returns {*}
*/
prop(key: string): any;
/**
* Checks whether the element/array of elements exists.
* @returns {boolean}
*/
exists(): boolean;
/**
* Finds descendant nodes matching selector and returns a new `ShallowWrapper`
* without re-rendering found nodes.
* @param {string|Function} selector
* @returns {ShallowWrapper}
*/
find(selector: string | Function): ShallowWrapper;
/**
* Returns a string containing both text and props.
*/
textWithProps(): string;
}
import React from 'react';