teatest
teatest
Test helpers for Term2 programs. This is a Crystal port of the Go x/exp/teatest/v2 package from charmbracelet/ansi.
Installation
- Add the dependency to your
shard.yml:
dependencies:
teatest:
path: lib/teatest
- Run
shards install
Usage
require "teatest"
require "term2"
class Counter
include Term2::Model
def initialize(@n : Int32 = 0)
end
def init : Term2::Cmd
Term2::Cmds.none
end
def update(msg : Term2::Msg) : {Term2::Model, Term2::Cmd}
case msg
when Term2::KeyMsg
if msg.code == Ultraviolet::KeyEnter
return {self, nil}
end
end
{self, nil}
end
def view : String
"count=#{@n}\n"
end
end
tm = Teatest.new_test_model(Counter.new)
Teatest.wait_for(tm.output, ->(b : Bytes) { String.new(b).includes?("count=") })
tm.quit
Golden output
Teatest.require_equal_output(self, tm.output.to_slice)
Development
crystal tool formatcrystal spec
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- dsisnero - creator and maintainer
Repository
teatest
Owner
Statistic
- 0
- 0
- 0
- 1
- 2
- 1 day ago
- February 10, 2026
License
MIT License
Links
Synced at
Tue, 10 Feb 2026 22:20:55 GMT
Languages