Open-Source Wikis

/

Grafana

/

Packages

/

@grafana/test-utils

grafana/grafana

@grafana/test-utils

Shared Jest helpers and mocks. Source under packages/grafana-test-utils/.

What's inside

  • A Redux store factory (getMockStore) that mirrors Grafana's real configuration so component tests can render a tree that depends on the global store.
  • Theme-aware render wrappers that wrap React Testing Library's render with <ThemeProvider>, <I18nProvider>, and the appropriate router.
  • Common runtime mocks (mockBackendSrv, mockDataSourceSrv, mockLocationService).
  • MSW server bootstrapping helpers for tests that need to intercept HTTP.

Usage

import { render, screen, mockBackendSrv } from '@grafana/test-utils';

it('renders', () => {
  mockBackendSrv({ get: jest.fn().mockResolvedValue({}) });
  render(<MyThing />);
  expect(screen.getByText('Hello')).toBeInTheDocument();
});

See also

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

@grafana/test-utils – Grafana wiki | Factory