Skip to content

Testing

Because NextGrid measures real DOM viewport dimensions to allocate virtualized row and column pools, DOM-less unit environments like jsdom or happy-dom report 0 × 0 sizes and render no rows. Always run integration and UI tests in a real browser (Playwright, Cypress, or WebdriverIO).

  1. Locate by ARIA & Public Hooks: Target the root via getByRole('grid', { name: '...' }), cells via [role="gridcell"] or public .grid-cell[data-column-id="..."] attributes, and rows via aria-rowindex.
  2. Scroll Deterministic Targets Into View: Instead of guessing wheel pixel offsets, call grid.ensureRowVisible({ rowId }, 'center') or grid.ensureCellVisible(...) in your test harness before asserting cell text or clicking editors.
  3. Wait a Frame After API Mutations: NextGrid batches DOM binding into animation frames (requestAnimationFrame), so wait for the target locator or await page.evaluate(() => new Promise(requestAnimationFrame)) after calling setRowData or setSortModel.
  4. Assert Authoritative State via getState() / Events: Because offscreen rows are recycled out of the DOM, verify full selection, sort, filter, and expansion state via grid.getState() or grid.getSelectionState() rather than counting DOM elements.
import { expect, test } from '@playwright/test';
test('sorts orders and selects a row', async ({ page }) => {
await page.goto('/orders');
const grid = page.getByRole('grid', { name: 'Orders' });
await expect(grid).toBeVisible();
await grid.getByRole('columnheader', { name: 'Amount' }).click();
await expect(grid.locator('.grid-cell[data-column-id="id"]').first()).toBeVisible();
});