preact port of the the @testing-library/react-hooks library.
Currently, due to the use of
react-test-renderer, the react hooks testing library most likely will never be compatible with preact.
Why not another library?
At the time of writing, a library did not exist to test preact hooks.
When to use this library
- You're writing a library with one or more custom hooks that are not directly tied to a component
- You have a complex hook that is difficult to test through component interactions
When not to use this library
- Your hook is defined alongside a component and is only used there
- Your hook is easy to test by just testing the components using it
Install with your favorite package manager
yarn add -D @testing-library/preact-hooks OR npm install --save-dev @testing-library/preact-hooks
Example #1: Basic
;;test'should increment counter',;
Example #2: Wrapped Components
Sometimes, hooks may need access to values or functionality outside of itself that are provided by a context provider or some other HOC.
In our test, we simply use CoounterStepProvider as the wrapper when rendering the hook:
test'should use custom step when incrementing',
@ts-nocheckflag from tests
- fix disabled auto clean up tests