Configure Vitest for IntersectionObserver mocking
mainIf you are using Vitest without globals, you must manually set up and reset the intersection mocking in your test files or a setup file.
import { vi, beforeEach, afterEach } from "vitest";
import {
setupIntersectionMocking,
resetIntersectionMocking,
} from "react-intersection-observer/test-utils";
beforeEach(() => {
setupIntersectionMocking(vi.fn);
});
afterEach(() => {
resetIntersectionMocking();
});import { vi, beforeEach, afterEach } from "vitest";
import {
setupIntersectionMocking,
resetIntersectionMocking,
} from "react-intersection-observer/test-utils";
beforeEach(() => {
setupIntersectionMocking(vi.fn);
});
afterEach(() => {
resetIntersectionMocking();
});