mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 11:09:17 -07:00
test: run model with provided input and check output
This commit is contained in:
39
tea_test.go
Normal file
39
tea_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package tea
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testModel struct{}
|
||||
|
||||
func (m testModel) Init() Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m testModel) Update(msg Msg) (Model, Cmd) {
|
||||
switch msg.(type) {
|
||||
case KeyMsg:
|
||||
return m, Quit
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m testModel) View() string {
|
||||
return "success\n"
|
||||
}
|
||||
|
||||
func TestTeaModel(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
var in bytes.Buffer
|
||||
in.Write([]byte("q"))
|
||||
|
||||
p := NewProgram(testModel{}, WithInput(&in), WithOutput(&buf))
|
||||
if err := p.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if buf.Len() == 0 {
|
||||
t.Fatal("no output")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user