📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP →

react-intersection-observer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-intersection-observer - npm Package Compare versions

Comparing version

to
9.15.1

{
"name": "react-intersection-observer",
"version": "9.15.0",
"version": "9.15.1",
"description": "Monitor if a component is inside the viewport, using IntersectionObserver API",

@@ -5,0 +5,0 @@ "type": "commonjs",

@@ -43,14 +43,24 @@ "use strict";

var DeprecatedReactTestUtils = __toESM(require("react-dom/test-utils"));
var isMocking = false;
var observers = /* @__PURE__ */ new Map();
var originalIntersectionObserver = typeof window !== "undefined" ? window.IntersectionObserver : void 0;
if (typeof window !== "undefined" && typeof beforeAll !== "undefined" && typeof beforeEach !== "undefined" && typeof afterEach !== "undefined") {
const initMocking = () => {
if (typeof jest !== "undefined") setupIntersectionMocking(jest.fn);
else if (typeof vi !== "undefined") {
setupIntersectionMocking(vi.fn);
function testLibraryUtil() {
if (typeof vi !== "undefined") return vi;
if (typeof jest !== "undefined") return jest;
return void 0;
}
function isMocking() {
const util = testLibraryUtil();
if (util && typeof util.isMockFunction === "function") {
return util.isMockFunction(window.IntersectionObserver);
}
return false;
}
if (typeof window !== "undefined" && typeof beforeEach !== "undefined" && typeof afterEach !== "undefined") {
beforeEach(() => {
const util = testLibraryUtil();
if (util) {
setupIntersectionMocking(util.fn);
}
};
beforeAll(initMocking);
beforeEach(initMocking);
observers.clear();
});
afterEach(resetIntersectionMocking);

@@ -66,3 +76,3 @@ }

function warnOnMissingSetup() {
if (isMocking) return;
if (isMocking()) return;
console.error(

@@ -85,3 +95,2 @@ `React Intersection Observer was not configured to handle mocking.

function setupIntersectionMocking(mockFn) {
if (isMocking) return;
window.IntersectionObserver = mockFn((cb, options = {}) => {

@@ -112,3 +121,2 @@ var _a, _b, _c;

});
isMocking = true;
}

@@ -124,3 +132,2 @@ function resetIntersectionMocking() {

window.IntersectionObserver = originalIntersectionObserver;
isMocking = false;
}

@@ -127,0 +134,0 @@ function triggerIntersection(elements, trigger, observer, item) {

Sorry, the diff of this file is not supported yet