| name | tui-testing-debug |
| description | Methods for debugging and unit testing Bubble Tea TUIs without a visible terminal. Use when this capability is needed. |
| metadata | {"author":"anishshah1803"} |
What I do
- Implement logging to file (standard TUI debugging).
- Setup
teatest for automated TUI testing.
- Handle terminal recovery logic.
Best Practices
- Log to File: Since
fmt.Println breaks the TUI, use tea.LogToFile("debug.log", "prefix") for development.
- Testing with Teatest: Use
github.com/charmbracelet/bubbletea/teatest to simulate keypresses and assert the final view string.
- Panic Recovery: Use
tea.WithAltScreen() and ensure errors are returned through p.Run() rather than calling os.Exit inside the model.
Example: File Logging
if len(os.Getenv("DEBUG")) > 0 {
f, err := tea.LogToFile("debug.log", "debug")
if err != nil {
log.Fatal(err)
}
defer f.Close()
}
---
> Converted and distributed by [TomeVault](https:
<!-- tomevault:4.0:skill_md:2026-04-16 -->