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).
Recommended Locator & Assertion Patterns
Section titled “Recommended Locator & Assertion Patterns”- 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 viaaria-rowindex. - Scroll Deterministic Targets Into View: Instead of guessing wheel pixel offsets, call
grid.ensureRowVisible({ rowId }, 'center')orgrid.ensureCellVisible(...)in your test harness before asserting cell text or clicking editors. - Wait a Frame After API Mutations: NextGrid batches DOM binding into animation frames (
requestAnimationFrame), so wait for the target locator orawait page.evaluate(() => new Promise(requestAnimationFrame))after callingsetRowDataorsetSortModel. - Assert Authoritative State via
getState()/ Events: Because offscreen rows are recycled out of the DOM, verify full selection, sort, filter, and expansion state viagrid.getState()orgrid.getSelectionState()rather than counting DOM elements.
Playwright Example
Section titled “Playwright Example”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();});