File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -40,19 +40,35 @@ import { renderHook, act } from '@testing-library/react-hooks'
40
40
import { CounterStepProvider , useCounter } from ' ./counter'
41
41
42
42
test (' should use custom step when incrementing' , () => {
43
- const wrapper = ({ children }) => < CounterStepProvider step= {2 }> {children}< / CounterStepProvider>
44
- const { result } = renderHook (() => useCounter (), { wrapper })
43
+ const wrapper = ({ children, step }) => (
44
+ < CounterStepProvider step= {step}> {children}< / CounterStepProvider>
45
+ )
46
+ const { result , rerender } = renderHook (() => useCounter (), {
47
+ wrapper,
48
+ initialProps: {
49
+ step: 2
50
+ }
51
+ })
45
52
46
53
act (() => {
47
54
result .current .increment ()
48
55
})
49
56
50
57
expect (result .current .count ).toBe (2 )
58
+
59
+ rerender ({ step: - 2 })
60
+
61
+ act (() => {
62
+ result .current .increment ()
63
+ })
64
+
65
+ expect (result .current .count ).toBe (0 )
51
66
})
52
67
```
53
68
54
- The ` wrapper ` option will accept any React component, but it ** must** render ` children ` in order for
55
- the test component to render and the hook to execute.
69
+ The ` wrapper ` option will accept any React component and access the ` initialProps ` option and new
70
+ props from ` rerender ` method as its properties, but it ** must** render ` children ` in order for the
71
+ test component to render and the hook to execute.
56
72
57
73
### ESLint Warning
58
74
You can’t perform that action at this time.
0 commit comments