How to use the @testing-library/react-hooks.act function in @testing-library/react-hooks

To help you get started, we’ve selected a few @testing-library/react-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github testing-library / react-hooks-testing-library / test / typescript / act.ts View on Github external
function checkTypesWithVoidResult() {
  const callback = () => {}
  act(callback)
}
github testing-library / react-hooks-testing-library / test / typescript / act.ts View on Github external
function checkTypesWithUndefinedResult() {
  const callback = () => undefined
  act(callback)
}
github kube-js / kube-ts-react-client / src / utils / hooks / useForm / index.spec.tsx View on Github external
it('when validation and submit successful', async () => {
      const { result, waitForNextUpdate } = renderHook(() =>
        useForm(options)
      );

      const func: any = async () => {
        result.current.handleSubmit(event);

        await waitForNextUpdate();
      };

      await act(func);

      expect(result.current).toMatchSnapshot();
      expect(options.onSubmit).toBeCalledWith(values);
    });

@testing-library/react-hooks

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

MIT
Latest version published 2 years ago

Package Health Score

82 / 100
Full package analysis