feat: tea.Batch returns nil if all cmds are nil (#217)

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker
2022-02-03 12:08:34 -03:00
committed by GitHub
parent a09e0e80cb
commit 9a06319ff1
2 changed files with 34 additions and 2 deletions

View File

@@ -80,3 +80,28 @@ func TestSequentially(t *testing.T) {
})
}
}
func TestBatch(t *testing.T) {
t.Run("nil cmd", func(t *testing.T) {
if b := Batch(nil); b != nil {
t.Fatalf("expected nil, got %+v", b)
}
})
t.Run("empty cmd", func(t *testing.T) {
if b := Batch(); b != nil {
t.Fatalf("expected nil, got %+v", b)
}
})
t.Run("single cmd", func(t *testing.T) {
b := Batch(Quit)()
if l := len(b.(batchMsg)); l != 1 {
t.Fatalf("expected a []Cmd with len 1, got %d", l)
}
})
t.Run("mixed nil cmds", func(t *testing.T) {
b := Batch(nil, Quit, nil, Quit, nil, nil)()
if l := len(b.(batchMsg)); l != 2 {
t.Fatalf("expected a []Cmd with len 2, got %d", l)
}
})
}