Skip to content

Commit d760c65

Browse files
authored
Update README.md
1 parent ac0f2cb commit d760c65

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ it('shows the right lines on desktop and mobile', () => {
3535
```
3636
3737
## Mock intersection observer
38-
Mocks intersection observer
38+
Provides a way of triggering intersection observer events
3939
4040
Example, using `React Testing Library`:
4141
@@ -55,3 +55,17 @@ it('loads the image when the component is in the viewport', () => {
5555
expect(getByAltText('alt text')).toBeInTheDocument()
5656
})
5757
```
58+
59+
### API
60+
61+
`mockIntersectionObserver` returns an object, that has several useful methods:
62+
63+
#### .enterNode(node, desc) and .leaveNode(node, desc)
64+
Triggers the intersection observer callback with only one node
65+
and `isIntersected` set to `true` (for `enterNode`) or `false` (for `leaveNode`).
66+
Other `IntersectionObserverEntry` params can be passed as `desc` argument
67+
68+
#### .enterAll(desc) and .leaveAll(desc)
69+
Triggers the intersection observer callback for all of the observed nodes
70+
and `isIntersected` set to `true` (for `enterAll`) or `false` (for `leaveAll`).
71+
Other `IntersectionObserverEntry` params can be passed as `desc` argument

0 commit comments

Comments
 (0)