UNPKG

enzyme-context

Version:

Enzyme Context is a pluggable library which simplifies the process of testing components that rely on react context.

38 lines 2.17 kB
import { ReactElement } from 'react'; import { EnzymePlugin } from 'enzyme-context-utils'; import { ReactWrapper, ShallowWrapper } from 'enzyme'; import { EnzymePlugins, GetOptions, GetControllers, GetContextWrapper } from './Types'; declare type UpdaterFns = NonNullable<ReturnType<EnzymePlugin<any, any>>['updater']>[]; declare type PluginReturns<P extends EnzymePlugins, O extends GetOptions<any, P>> = { node: ReactElement<any>; options: NonNullable<O>; controllers: GetControllers<P>; updaters: UpdaterFns; }; /** * Call each plugin (enzyme-context plugins are functions) and aggregate each plugin's results * into a single object. * * @param plugins a mapping of user-supplied name to plugin * @param node the react element being mounted * @param options enzyme mount/shallow options (plus any additional plugin-defined options) */ export declare function executePlugins<P extends EnzymePlugins, O extends GetOptions<any, P>>(plugins: P, node: ReactElement<any>, options: NonNullable<O>): PluginReturns<P, O>; /** * First, calls every plugin's [`updater` function](https://github.com/trialspark/enzyme-context/blob/aa66183f78eb3e80f8712d1aa8a2736307cabe02/docs/authoring-plugins.md#returns). Then, it patches the enzyme ReactWrapper/ShallowWrapper to call every plugin's unmount handler when unount() is called. * * @param pluginResults the data returned by calling `executePlugins` * @param wrapper an enzyme wrapper */ export declare function hookIntoLifecycle<PR extends PluginReturns<any, any>, W extends ReactWrapper | ShallowWrapper>(pluginResults: PR, wrapper: W): void; /** * Adds all of the plugins' controllers as attributes of the Enzyme wrapper. * It also adds the deprecated `controller` attribute, but logs to tell the user * it is deprecated. * * @param wrapper The `ReactWrapper` or `ShallowWrapper` to decorate * @param plugins All the executed plugins */ export declare function decorateEnzymeWrapper<EW extends ReactWrapper<any, any, any> | ShallowWrapper<any, any, any>, P extends EnzymePlugins>(wrapper: EW, plugins: PluginReturns<P, any>): GetContextWrapper<EW, P>; export {}; //# sourceMappingURL=Utils.d.ts.map