Using the React Hooks Testing Library

In addition to the React Hooks Testing Library, we also need a special renderer for React. To render React components to the DOM, we used react-dom; for tests, we can use the react-test-renderer. We are now going to install the React Hooks Testing Library and the react-test-renderer via npm:

> npm install --save-dev @testing-library/react-hooks react-test-renderer

The React Hooks Testing Library should be used in the following circumstances:

  • When writing libraries that define Hooks
  • When you have Hooks that are used throughout multiple components (global Hooks)

However, the library should not be used when a Hook is only defined and used in a single component (local Hooks).

In that case, we should test the component directly using the React Testing Library. However, testing React components is beyond the scope of this book. More information about testing components can be found on the library website: https://testing-library.com/docs/react-testing-library/intro.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.186.201