name: tui-test-renderer description: 为TUI组件设置测试工具,使用ink-testing-library和Bubble Tea测试。 allowed-tools: Read, Write, Edit, Bash, Glob, Grep
TUI 测试渲染器
为TUI组件设置测试工具。
生成的模式
Ink 测试
import { render } from 'ink-testing-library';
import React from 'react';
import { MyComponent } from './MyComponent';
test('正确渲染', () => {
const { lastFrame, stdin } = render(<MyComponent />);
expect(lastFrame()).toContain('期望的文本');
stdin.write('\r'); // 模拟回车键
expect(lastFrame()).toContain('回车后');
});
Bubble Tea 测试
import (
tea "github.com/charmbracelet/bubbletea"
"testing"
)
func TestModel(t *testing.T) {
m := initialModel()
m, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
view := m.View()
if !strings.Contains(view, "期望内容") {
t.Errorf("期望视图包含 '期望内容'")
}
}
目标流程
- tui-application-framework
- cli-unit-integration-testing