nexa-test-utils API Reference
The nexa-test-utils package provides a set of utilities designed for testing Nexa components and reactivity systems in virtual DOM or jsdom environments with simplicity and speed.
render
Mounts a Nexa component into a virtual document container and returns queries to interact with it.
Signature
typescript
export interface RenderResult {
container: HTMLElement
debug: () => void
unmount: () => void
}
export function render(
component: any,
props?: Record<string, any>
): Promise<RenderResult>Usage Example
javascript
import { describe, it, expect } from 'vitest'
import { render } from 'nexa-test-utils'
import MyComponent from '../src/MyComponent.nexa'
describe('MyComponent', () => {
it('renders correctly', async () => {
const { container } = await render(MyComponent, { title: 'Hello Nexa' })
expect(container.innerHTML).toContain('Hello Nexa')
})
})fireEvent
Triggers synthetic DOM events on mount nodes, ensuring proper reactive microtask updates.
Supported Events
click(element: HTMLElement, eventInit?: EventInit): voidinput(element: HTMLElement, value: string): voidchange(element: HTMLElement): voidsubmit(element: HTMLElement): voidkeyDown(element: HTMLElement, key: string): void
waitFor
Suspends execution until the provided assertion callback stops throwing, or the internal timeout limit is reached.
Signature
typescript
export function waitFor(
assertion: () => void | Promise<void>,
options?: { timeout?: number; interval?: number }
): Promise<void>