Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
erozak committed Jul 23, 2020
1 parent b94af2b commit 482ee46
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions docs/usage/advanced-hooks.md
Expand Up @@ -40,19 +40,35 @@ import { renderHook, act } from '@testing-library/react-hooks'
import { CounterStepProvider, useCounter } from './counter'

test('should use custom step when incrementing', () => {
const wrapper = ({ children }) => <CounterStepProvider step={2}>{children}</CounterStepProvider>
const { result } = renderHook(() => useCounter(), { wrapper })
const wrapper = ({ children, step }) => (
<CounterStepProvider step={step}>{children}</CounterStepProvider>
)
const { result, rerender } = renderHook(() => useCounter(), {
wrapper,
initialProps: {
step: 2
}
})

act(() => {
result.current.increment()
})

expect(result.current.count).toBe(2)

rerender({ step: -2 })

act(() => {
result.current.increment()
})

expect(result.current.count).toBe(0)
})
```

The `wrapper` option will accept any React component, but it **must** render `children` in order for
the test component to render and the hook to execute.
The `wrapper` option will accept any React component and access the `initialProps` option and new
props from `rerender` method as its properties, but it **must** render `children` in order for the
test component to render and the hook to execute.

### ESLint Warning

Expand Down

0 comments on commit 482ee46

Please sign in to comment.