Setup
Install the test stack you need — FormEngine forms render as regular DOM, so any React testing tool works.Rendering a form in a test
Testing user input
UseuserEvent (not fireEvent) — it simulates real typing, focus, and keyboard events:
Testing validation
Assert that invalid input produces the expected error message:Testing submit with a mock API
Mockfetch (or your API client) and assert the request body:
Testing with initialData
Pre-populate a form to test edit flows:Testing imperatively via viewerRef
For complex flows, grab the viewer ref and call methods directly:Accessibility tests
Run axe against every form — catch contrast issues, missing labels, and bad ARIA early:Testing conditional logic
When a field only appears under certain conditions, assert both states:Testing custom actions
Provide a mockactions object and assert it was called with the right event args:
E2E with Playwright
For full-browser tests, Playwright drives a real browser against your running app:Common pitfalls
waitFormissing on async validation — validation runs async; alwaysawait findBy*orwaitForfor errors.- Testing CSS classes instead of state — assert on
aria-invalid, not.has-error. CSS can change; semantics shouldn’t. - Using
getByTextfor form labels — usegetByLabelTextso you test the label-input association. - Over-mocking — let the real
FormViewerrun. Only mock network calls and timers. - Not awaiting
userEvent— everyuserEvent.*call returns a promise in v14+.
Related
- Accessibility guide — axe checks and WCAG criteria
- Form submission — what to mock when testing submit
- Validation — validation rules you’ll assert against