Skip to content

Commit 9c8de02

Browse files
committed
Removed testHook from api
1 parent 7a0a1f0 commit 9c8de02

File tree

1 file changed

+1
-67
lines changed
  • docs/react-testing-library

1 file changed

+1
-67
lines changed

docs/react-testing-library/api.md

+1-67
Original file line numberDiff line numberDiff line change
@@ -253,70 +253,4 @@ set up your framework.
253253
This is a light wrapper around the
254254
[`react-dom/test-utils` `act` function](https://reactjs.org/docs/test-utils.html#act).
255255
All it does is forward all arguments to the act function if your version of
256-
react supports `act`.
257-
258-
## `testHook`
259-
260-
`testHook` is a utility to test custom hooks. It is designed to help test
261-
reusable hooks in isolation.
262-
263-
You should also write integration tests for components using custom hooks, and
264-
one-off hooks should be tested as part of the component instead.
265-
266-
**Usage**
267-
268-
```jsx
269-
import { testHook } from 'react-testing-libary'
270-
271-
testHook(hook[, renderOptions])
272-
```
273-
274-
**Arguments**
275-
276-
- `hook` customHook to test
277-
- `renderOptions` options object to pass to the underlying `render`. See
278-
[render options](#render-options). This is mostly useful for wrapping the hook
279-
with a context provider.
280-
281-
**Returns**
282-
283-
```jsx
284-
const { rerender, unmount, result } = testHook(hook)
285-
```
286-
287-
- `rerender` Call this function to render the wrapper again, i.e., to test that
288-
the hook handles props changes
289-
- `unmount` Call this to unmount the component, i.e., to test side-effects and
290-
cleanup behavior
291-
- `result` An object that acts like a React ref with a `current` property
292-
pointing to the last value the hook returned. For example:
293-
`expect(result.current.count).toBe(0)`
294-
295-
**Example**
296-
297-
```jsx
298-
// Example custom hook
299-
function useCounter({ initialCount = 0, step = 1 } = {}) {
300-
const [count, setCount] = React.useState(initialCount)
301-
const increment = () => setCount(c => c + step)
302-
const decrement = () => setCount(c => c - step)
303-
return { count, increment, decrement }
304-
}
305-
```
306-
307-
```jsx
308-
// Test using the `result` ref
309-
test('returns result ref with latest result from hook execution', () => {
310-
const { result } = testHook(useCounter)
311-
312-
expect(result.current.count).toBe(0)
313-
act(() => result.current.increment())
314-
expect(result.current.count).toBe(1)
315-
})
316-
```
317-
318-
**More**
319-
320-
- [More Examples](/docs/example-react-hooks)
321-
- [Tests](https://github.com/kentcdodds/react-testing-library/blob/master/src/__tests__/test-hook.js)
322-
- [Types](https://github.com/kentcdodds/react-testing-library/blob/master/typings/index.d.ts)
256+
react supports `act`.

0 commit comments

Comments
 (0)