@testing-library/react-hooks

  • Version 7.0.2
  • Published
  • 137 kB
  • 5 dependencies
  • MIT license

Install

npm i @testing-library/react-hooks
yarn add @testing-library/react-hooks
pnpm add @testing-library/react-hooks

Overview

Simple and complete React hooks testing utilities that encourage good testing practices.

Index

Variables

variable act

const act: Act;

    Functions

    function addCleanup

    addCleanup: (callback: import('./types').CleanupCallback) => () => void;

      function cleanup

      cleanup: () => Promise<void>;

        function removeCleanup

        removeCleanup: (callback: import('./types').CleanupCallback) => void;

          function renderHook

          renderHook: <TProps, TResult>(
          callback: (props: TProps) => TResult,
          options?: RenderHookOptions<TProps>
          ) => RenderHookResult<TProps, TResult, Renderer<TProps>>;

            function suppressErrorOutput

            suppressErrorOutput: () => () => void;

              Type Aliases

              type Act

              type Act = {
              (callback: () => Promise<void | undefined>): Promise<undefined>;
              (callback: () => void | undefined): void;
              };

                type AsyncUtils

                type AsyncUtils = {
                waitFor: WaitFor;
                waitForValueToChange: WaitForValueToChange;
                waitForNextUpdate: WaitForNextUpdate;
                };

                  type CleanupCallback

                  type CleanupCallback = () => Promise<void> | void;

                    type CreateRenderer

                    type CreateRenderer<
                    TProps,
                    TResult,
                    TRendererOptions extends object,
                    TRenderer extends Renderer<TProps>
                    > = (props: RendererProps<TProps, TResult>, options: TRendererOptions) => TRenderer;

                      type ReactHooksRenderer

                      type ReactHooksRenderer = {
                      renderHook: <TProps, TResult>(
                      callback: (props: TProps) => TResult,
                      options?: RenderHookOptions<TProps>
                      ) => RenderHookResult<TProps, TResult>;
                      act: Act;
                      cleanup: () => Promise<void>;
                      addCleanup: (callback: CleanupCallback) => () => void;
                      removeCleanup: (callback: CleanupCallback) => void;
                      suppressErrorOutput: () => () => void;
                      };

                        type ReactHooksServerRenderer

                        type ReactHooksServerRenderer = Omit<ReactHooksRenderer, 'renderHook'> & {
                        renderHook: <TProps, TResult>(
                        callback: (props: TProps) => TResult,
                        options?: RenderHookOptions<TProps>
                        ) => ServerRenderHookResult<TProps, TResult>;
                        };

                          type Renderer

                          type Renderer<TProps> = {
                          render: (props?: TProps) => void;
                          rerender: (props?: TProps) => void;
                          unmount: () => void;
                          act: Act;
                          };

                            type RendererOptions

                            type RendererOptions<TProps> = {
                            wrapper?: WrapperComponent<TProps>;
                            };

                              type RendererProps

                              type RendererProps<TProps, TResult> = {
                              callback: (props: TProps) => TResult;
                              setError: (error: Error) => void;
                              setValue: (value: TResult) => void;
                              };

                                type RenderHookOptions

                                type RenderHookOptions<TProps> = BaseRenderHookOptions<TProps> & {
                                wrapper?: WrapperComponent<TProps>;
                                };

                                  type RenderHookResult

                                  type RenderHookResult<
                                  TProps,
                                  TValue,
                                  TRenderer extends Renderer<TProps> = Renderer<TProps>
                                  > = ResultContainer<TValue> &
                                  Omit<Renderer<TProps>, 'render' | 'act'> &
                                  Omit<TRenderer, keyof Renderer<TProps>> &
                                  AsyncUtils;

                                    type RenderResult

                                    type RenderResult<TValue> = {
                                    readonly all: Array<TValue | Error>;
                                    readonly current: TValue;
                                    readonly error?: Error;
                                    };

                                      type ResultContainer

                                      type ResultContainer<TValue> = {
                                      result: RenderResult<TValue>;
                                      };

                                        type ServerRenderer

                                        type ServerRenderer<TProps> = Renderer<TProps> & {
                                        hydrate: () => void;
                                        };

                                          type ServerRenderHookResult

                                          type ServerRenderHookResult<
                                          TProps,
                                          TValue,
                                          TRenderer extends ServerRenderer<TProps> = ServerRenderer<TProps>
                                          > = RenderHookResult<TProps, TValue, TRenderer>;

                                            type WaitFor

                                            type WaitFor = (
                                            callback: () => boolean | void,
                                            options?: WaitForOptions
                                            ) => Promise<void>;

                                              type WaitForNextUpdate

                                              type WaitForNextUpdate = (options?: WaitForNextUpdateOptions) => Promise<void>;

                                                type WaitForNextUpdateOptions

                                                type WaitForNextUpdateOptions = Pick<WaitOptions, 'timeout'>;

                                                  type WaitForOptions

                                                  type WaitForOptions = WaitOptions;

                                                    type WaitForValueToChange

                                                    type WaitForValueToChange = (
                                                    selector: () => unknown,
                                                    options?: WaitForValueToChangeOptions
                                                    ) => Promise<void>;

                                                      type WaitForValueToChangeOptions

                                                      type WaitForValueToChangeOptions = WaitOptions;

                                                        type WaitOptions

                                                        type WaitOptions = {
                                                        interval?: number | false;
                                                        timeout?: number | false;
                                                        };

                                                          type WrapperComponent

                                                          type WrapperComponent<TProps> = ComponentType<TProps>;

                                                            Package Files (4)

                                                            Dependencies (5)

                                                            Dev Dependencies (17)

                                                            Peer Dependencies (3)

                                                            Badge

                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@testing-library/react-hooks.

                                                            • Markdown
                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@testing-library/react-hooks)
                                                            • HTML
                                                              <a href="https://www.jsdocs.io/package/@testing-library/react-hooks"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>