Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-intersection-observer

Package Overview
Dependencies
Maintainers
1
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-intersection-observer - npm Package Compare versions

Comparing version 8.33.0 to 8.33.1

2

package.json
{
"name": "react-intersection-observer",
"version": "8.33.0",
"version": "8.33.1",
"description": "Monitor if a component is inside the viewport, using IntersectionObserver API",

@@ -5,0 +5,0 @@ "source": "src/index.tsx",

@@ -257,4 +257,8 @@ # react-intersection-observer

Import the methods from `react-intersection-observer/test-utils`.
You can use these test utilities as imports in individual files OR you can globally mock Intersection Observer for all Jest tests. If you use a library or an application with a lot of Intersection Observer usage, you may wish to globally mock it; however, the official recommendation is to be purposeful about your mocking and do so on a per-usage basis.
#### Indvidual Methods
Import these from `react-intersection-observer/test-utils`.
**`mockAllIsIntersecting(isIntersecting:boolean | number)`**

@@ -271,2 +275,27 @@ Set `isIntersecting` on all current IntersectionObserver instances.

#### Global Intersection Observer Behavior
##### Use Fallback
You can create a [Jest setup file](https://jestjs.io/docs/configuration#setupfiles-array) that leverages the [unsupported fallback](https://github.com/thebuilder/react-intersection-observer#unsupported-fallback) option. In this case, you only mock the IntersectionObserver in test files were you actively import `react-intersection-observer/test-utils`:
```js
import { defaultFallbackInView } from 'react-intersection-observer';
defaultFallbackInView(true); // or 'false' - whichever consistent behavior makes the most sense for your use case.
```
##### Mock Everywhere
In your Jest config, add `'react-intersection-observer/test-utils'` to the array value for the [`setupFilesAfterEnv`](https://jestjs.io/docs/configuration#setupfilesafterenv-array) option.
```js
module.exports = {
// other config lines
setupFilesAfterEnv: ['react-intersection-observer/test-utils'],
// other config lines
};
```
### Test Example

@@ -273,0 +302,0 @@

@@ -134,4 +134,4 @@ "use strict";

}
throw new Error('Failed to find IntersectionObserver for element. Is it being observer?');
throw new Error('Failed to find IntersectionObserver for element. Is it being observed?');
}
exports.intersectionMockInstance = intersectionMockInstance;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc