TUI测试渲染器 tui-test-renderer

该技能用于为终端用户界面(TUI)组件建立自动化测试环境。它提供了使用ink-testing-library(针对React组件)和Bubble Tea(针对Go语言模型)进行单元测试和集成测试的实用工具和代码模式。关键词:TUI测试,终端界面测试,ink测试库,Bubble Tea测试,CLI组件测试,自动化测试工具。

测试 0 次安装 0 次浏览 更新于 2/23/2026

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