@teaui/core
Version:
A high-level terminal UI library for Node
75 lines (74 loc) • 2.1 kB
TypeScript
/**
* Test utilities for headless component rendering and interaction.
*
* Usage:
* const t = testRender(<view>, {width: 40, height: 10})
* expect(t.terminal.textContent()).toContain('Hello')
* expect(t.terminal.styleOf('Hello')?.bold).toBe(true)
*
* t.sendKey('a')
* t.sendKey('tab')
* t.sendKey('return', {ctrl: true})
* t.sendMouse('mouse.button.down', {x: 5, y: 2})
*
* // Re-renders automatically after events, query again:
* expect(t.terminal.charAt(0, 0)).toBe('a')
*/
import { type KeyName } from '@teaui/term';
import type { TestTerminal } from './TestTerminal.js';
import type { View } from './View.js';
import { type SystemMouseEvent } from './events/index.js';
declare class TestScreen {
#private;
readonly options: {
width: number;
height: number;
isFocused?: boolean;
};
constructor(view: View, options: {
width: number;
height: number;
isFocused?: boolean;
});
get terminal(): TestTerminal;
get view(): View;
/**
* Advance time by `dt` milliseconds, triggering any registered tick
* animations and re-rendering.
*/
tick(dt: number): void;
render(): void;
sendKey(key: KeyName, mods?: {
ctrl?: boolean;
alt?: boolean;
gui?: boolean;
shift?: boolean;
}): void;
sendMouse(name: SystemMouseEvent['name'], pos: {
x: number;
y: number;
}, mods?: {
ctrl?: boolean;
alt?: boolean;
gui?: boolean;
shift?: boolean;
}): void;
sendPaste(text: string): void;
}
/**
* Render a component headlessly and return a test harness for interaction testing.
*
* @example
* ```ts
* const t = testRender(new Input({value: 'hello'}), {width: 20, height: 1})
* expect(t.terminal.textContent()).toContain('hello')
* t.sendKey('!') // type a character
* expect(t.terminal.textContent()).toContain('hello!')
* ```
*/
export declare function testRender(view: View, size: {
width: number;
height: number;
isFocused?: boolean;
}): TestScreen;
export {};