Gathering detailed insights and metrics for testing-library-react-hooks-mf
The total size of the npm registry is estimated to be over 4 terabytes. This includes all the packages, versions, and metadata stored in the registry.
Gathering detailed insights and metrics for testing-library-react-hooks-mf
The total size of the npm registry is estimated to be over 4 terabytes. This includes all the packages, versions, and metadata stored in the registry.
npm install testing-library-react-hooks-mf
61.4
Supply Chain
92.7
Quality
78.3
Maintenance
100
Vulnerability
100
License
5,261 Stars
1,189 Commits
233 Forks
31 Watching
16 Branches
85 Contributors
Updated on 21 Nov 2024
TypeScript (97.74%)
JavaScript (2.26%)
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
133.3%
7
Compared to previous week
Last month
-77.3%
17
Compared to previous month
Last year
0%
92
Compared to previous year
2
4
Simple and complete React hooks testing utilities that encourage good testing practices.
If you are using the current version of react-testing-library
, replace
1import { renderHook } from '@testing-library/react-hooks'
with
1import { renderHook } from '@testing-library/react'
Once replaced, @testing-library/react-hooks
can be uninstalled.
As part of the changes for React 18, it has been decided that the renderHook
API provided by this
library will instead be included as official additions to both react-testing-library
(PR) and
react-native-testing-library
(PR) with the intention being
to provide a more cohesive and consistent implementation for our users.
Please be patient as we finalise these changes in the respective testing libraries.
In the mean time you can install @testing-library/react@^13.1
You're writing an awesome custom hook and you want to test it, but as soon as you call it you see the following error:
Invariant Violation: Hooks can only be called inside the body of a function component.
You don't really want to write a component solely for testing this hook and have to work out how you were going to trigger all the various ways the hook can be updated, especially given the complexities of how you've wired the whole thing together.
The react-hooks-testing-library
allows you to create a simple test harness for React hooks that
handles running them within the body of a function component, as well as providing various useful
utility functions for updating the inputs and retrieving the outputs of your amazing custom hook.
This library aims to provide a testing experience as close as possible to natively using your hook
from within a real component.
Using this library, you do not have to concern yourself with how to construct, render or interact with the react component in order to test your hook. You can just use the hook directly and assert the results.
useCounter.js
1import { useState, useCallback } from 'react' 2 3function useCounter() { 4 const [count, setCount] = useState(0) 5 6 const increment = useCallback(() => setCount((x) => x + 1), []) 7 8 return { count, increment } 9} 10 11export default useCounter
useCounter.test.js
1import { renderHook, act } from '@testing-library/react-hooks' 2import useCounter from './useCounter' 3 4test('should increment counter', () => { 5 const { result } = renderHook(() => useCounter()) 6 7 act(() => { 8 result.current.increment() 9 }) 10 11 expect(result.current.count).toBe(1) 12})
More advanced usage can be found in the documentation.
1npm install --save-dev @testing-library/react-hooks
react-hooks-testing-library
does not come bundled with a version of
react
to allow you to install the specific version you want
to test against. It also does not come installed with a specific renderer, we currently support
react-test-renderer
and
react-dom
. You only need to install one of them,
however, if you do have both installed, we will use react-test-renderer
as the default. For more
information see the
installation docs. Generally, the
installed versions for react
and the selected renderer should have matching versions:
1npm install react@^16.9.0 2npm install --save-dev react-test-renderer@^16.9.0
NOTE: The minimum supported version of
react
,react-test-renderer
andreact-dom
is^16.9.0
.
See the API reference.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Looking to contribute? Look for the Good First Issue label.
Please file an issue for bugs, missing documentation, or unexpected behavior.
Please file an issue to suggest new features. Vote on feature requests by adding a π. This helps maintainers prioritize what to work on.
For questions related to using the library, you can raise issue here, or visit a support community:
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 6/7 approved changesets -- score normalized to 8
Reason
0 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More