Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade the typings dependency and update the docs #414

Merged
merged 5 commits into from Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is a relatively niche feature, I think we would be better off have the basic example just with a wrapper and then some text about using props with the wrapper before showing the more complex example.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the revision as a new section "Providing Props". It may help to show the use case about using initialProps and the rerender method with wrapper.


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