Documentation ¶
Overview ¶
Package teatest provides helper functions to test tea.Model's.
Index ¶
- func RequireEqualOutput(tb testing.TB, out []byte)
- func WaitFor(tb testing.TB, r io.Reader, condition func(bts []byte) bool, ...)
- type FinalOpt
- type FinalOpts
- type Program
- type TestModel
- func (tm *TestModel) FinalModel(tb testing.TB, opts ...FinalOpt) tea.Model
- func (tm *TestModel) FinalOutput(tb testing.TB, opts ...FinalOpt) io.Reader
- func (tm *TestModel) GetProgram() *tea.Program
- func (tm *TestModel) Output() io.Reader
- func (tm *TestModel) Quit() error
- func (tm *TestModel) Send(m tea.Msg)
- func (tm *TestModel) Type(s string)
- func (tm *TestModel) WaitFinished(tb testing.TB, opts ...FinalOpt)
- type TestModelOptions
- type TestOption
- type WaitForOption
- type WaitingForContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequireEqualOutput ¶
RequireEqualOutput is a helper function to assert the given output is the expected from the golden files, printing its diff in case it is not.
Important: this uses the system `diff` tool.
You can update the golden files by running your tests with the -update flag.
func WaitFor ¶
func WaitFor( tb testing.TB, r io.Reader, condition func(bts []byte) bool, options ...WaitForOption, )
WaitFor keeps reading from r until the condition matches. Default duration is 1s, default check interval is 50ms. These defaults can be changed with WithDuration and WithCheckInterval.
Types ¶
type FinalOpt ¶
type FinalOpt func(opts *FinalOpts)
FinalOpt changes FinalOpts.
func WithFinalTimeout ¶
WithFinalTimeout allows to set a timeout for how long FinalModel and FinalOuput should wait for the program to complete.
func WithTimeoutFn ¶
WithTimeoutFn allows to define what happens when WaitFinished times out.
type FinalOpts ¶
type FinalOpts struct {
// contains filtered or unexported fields
}
FinalOpts represents the options for FinalModel and FinalOutput.
type TestModel ¶
type TestModel struct {
// contains filtered or unexported fields
}
TestModel is a model that is being tested.
func NewTestModel ¶
NewTestModel makes a new TestModel which can be used for tests.
func (*TestModel) FinalModel ¶
FinalModel returns the resulting model, resulting from program.Run(). This method only returns once the program has finished running or when it times out.
func (*TestModel) FinalOutput ¶
FinalOutput returns the program's final output io.Reader. This method only returns once the program has finished running or when it times out.
func (*TestModel) GetProgram ¶
GetProgram gets the TestModel's program.
type TestModelOptions ¶
type TestModelOptions struct {
// contains filtered or unexported fields
}
TestModelOptions defines all options available to the test function.
type WaitForOption ¶
type WaitForOption func(*WaitingForContext)
WaitForOption changes how a WaitFor will behave.
func WithCheckInterval ¶
func WithCheckInterval(d time.Duration) WaitForOption
WithCheckInterval sets how much time a WaitFor should sleep between every check.
func WithDuration ¶
func WithDuration(d time.Duration) WaitForOption
WithDuration sets how much time a WaitFor will wait for the condition.