vi.stubGlobal
basically does what it says on the packaging. It takes two arguments:
- The key on the global object that you want to stub.
- An mock implementation to use.
import { vi } from 'vitest';
const IntersectionObserverMock = vi.fn(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
takeRecords: vi.fn(),
unobserve: vi.fn(),
}));
vi.stubGlobal('IntersectionObserver', IntersectionObserverMock);