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
feat: add support for testing threshold values (#417)
This expands the `test-utils` to support defining a `threshold` value when checking for `isIntersecting`. Before you could only give a `boolean`.
This should allow you test more complex `threshold` based scenarios.
Copy file name to clipboardExpand all lines: README.md
+21-9Lines changed: 21 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,7 +153,7 @@ argument for the hooks.
153
153
|**delay** 🧪 | number | undefined | false | A number indicating the minimum delay in milliseconds between notifications from this observer for a given target. This must be set to at least `100` if `trackVisibility` is `true`. |
154
154
|**skip**| boolean | false | false | Skip creating the IntersectionObserver. You can use this to enable and disable the observer as needed. If `skip` is set while `inView`, the current state will still be kept. |
155
155
|**triggerOnce**| boolean | false | false | Only trigger the observer once. |
156
-
|**initialInView**| boolean | false | false | Set the initial value of the `inView` boolean. This can be used if you expect the element to be in the viewport to start with, and you want to trigger something when it leaves. |
156
+
|**initialInView**| boolean | false | false | Set the initial value of the `inView` boolean. This can be used if you expect the element to be in the viewport to start with, and you want to trigger something when it leaves. |
157
157
158
158
> ⚠️ When passing an array to `threshold`, store the array in a constant to
159
159
> avoid the component re-rendering too often. For example:
@@ -266,17 +266,18 @@ You can read more about this on these links:
266
266
In order to write meaningful tests, the `IntersectionObserver` needs to be
267
267
mocked. If you are writing your tests in Jest, you can use the included
268
268
`test-utils.js`. It mocks the `IntersectionObserver`, and includes a few methods
269
-
to assist with faking the `inView` state.
269
+
to assist with faking the `inView` state. When setting the `isIntersecting`
270
+
value you can pass either a `boolean` value or a threshold between `0` and `1`.
270
271
271
272
### `test-utils.js`
272
273
273
274
Import the methods from `react-intersection-observer/test-utils`.
0 commit comments