You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-29
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,9 @@ You don't really want to write a component solely for testing this hook and have
42
42
43
43
## The solution
44
44
45
-
The `react-hooks-testing-library` is built on top of the wonderful [`react-testing-library`](http://npm.im/react-testing-library) 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.
45
+
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.
46
+
47
+
Similarly to [`react-testing-library`](http://npm.im/react-testing-library), which this library draws much of it's inspiration from, it aims to provide a testing experience as close as possible to natively using your hook from within a real component.
46
48
47
49
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.
@@ -117,8 +117,9 @@ Renders a test component that will call the provided `callback`, including any h
117
117
#### Arguments
118
118
119
119
-`callback` (`function()`) - function to call each render. This function should call one or more hooks for testing.
120
-
-`options` (`object`) - accepts the [same options as `react-testing-library`'s `render` function](https://testing-library.com/docs/react-testing-library/api#render-options), as well as:
120
+
-`options` (`object`) - accept the following settings:
121
121
-`initialProps` (`object`) - the initial values to pass to the `callback` function
122
+
-`wrapper` (`component`) - pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating reusable custom render functions for common data providers
122
123
123
124
#### Returns
124
125
@@ -129,39 +130,17 @@ Renders a test component that will call the provided `callback`, including any h
129
130
-`rerender` (`function([newProps])`) - function to rerender the test component including any hooks called in the `callback` function. If `newProps` are passed, the will replace the `initialProps` passed the the `callback` function for future renders.
130
131
-`unmount` (`function()`) - function to unmount the test component, commonly used to trigger cleanup effects for `useEffect` hooks.
131
132
132
-
### `cleanup()`
133
-
134
-
Unmounts any React trees that were mounted with [renderHook](#renderhookcallback-options).
135
-
136
-
This is the same [`cleanup` function](https://testing-library.com/docs/react-testing-library/api#cleanup) that is exported by `react-testing-library`.
137
-
138
-
Optionally, it is possible to import `cleanup` in a global test file. Using that way, it isn't necessary to run `afterEach(cleanup)` on every test script.
This is the same [`act` function](https://testing-library.com/docs/react-testing-library/api#act) that is exported by `react-testing-library`.
135
+
This is the same [`act` function](https://reactjs.org/docs/hooks-faq.html#how-to-test-components-that-use-hooks) that is exported by `react-test-renderer`.
157
136
158
137
## Contributors
159
138
160
139
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
161
140
162
141
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
0 commit comments