Skip to content

Latest commit

 

History

History
17 lines (13 loc) · 473 Bytes

Mocking Globals.md

File metadata and controls

17 lines (13 loc) · 473 Bytes

vi.stubGlobal basically does what it says on the packaging. It takes two arguments:

  1. The key on the global object that you want to stub.
  2. 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);