Skip to main content
OpenTUI provides a comprehensive testing framework built on Bun’s test runner. The test renderer allows you to write unit and integration tests for your terminal UI without needing an actual terminal.

Test Renderer

The test renderer creates a virtual terminal environment for testing:

Test Renderer Options

Returned Utilities

Capturing Output

Character Frame

Capture the rendered output as a plain string:

Spans with Styling

Capture detailed styling information:

Mock Keyboard Input

Simulate keyboard input in your tests:

Typing Text

Pressing Keys

Available Key Codes

Convenience Methods

Mock Mouse Input

Simulate mouse interactions:

Mouse Operations

Mouse State

Mouse Buttons

Test Recorder

Record frames during rendering for analysis:

Recorder API

Recorded Frame Format

Spy Utility

Track function calls in tests:

Running Tests

Run All Tests

Run Specific Test File

Run with Filter

Watch Mode

Native Tests

Test the Zig core directly:

Filter Native Tests

Testing Best Practices

1. Use Descriptive Test Names

2. Test User Interactions

3. Test Edge Cases

4. Use Setup and Teardown

5. Test Async Operations

Example: Complete Integration Test

Next Steps

Performance

Optimize your application performance

Environment Variables

Configure with environment variables