teatest

package module
v0.0.0-...-6f71142 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package teatest provides helper functions to test tea.Model's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequireEqualOutput

func RequireEqualOutput(tb testing.TB, out []byte)

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

func WithFinalTimeout(d time.Duration) FinalOpt

WithFinalTimeout allows to set a timeout for how long FinalModel and FinalOuput should wait for the program to complete.

type FinalOpts

type FinalOpts struct {
	// contains filtered or unexported fields
}

FinalOpts represents the options for FinalModel and FinalOutput.

type Program

type Program interface {
	Send(tea.Msg)
}

Program defines the subset of the tea.Program API we need for testing.

type TestModel

type TestModel struct {
	// contains filtered or unexported fields
}

TestModel is a model that is being tested.

func NewTestModel

func NewTestModel(tb testing.TB, m tea.Model, options ...TestOption) *TestModel

NewTestModel makes a new TestModel which can be used for tests.

func (*TestModel) FinalModel

func (tm *TestModel) FinalModel(tb testing.TB, opts ...FinalOpt) tea.Model

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

func (tm *TestModel) FinalOutput(tb testing.TB, opts ...FinalOpt) io.Reader

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

func (tm *TestModel) GetProgram() *tea.Program

GetProgram gets the TestModel's program.

func (*TestModel) Output

func (tm *TestModel) Output() io.Reader

Output returns the program's current output io.Reader.

func (*TestModel) Quit

func (tm *TestModel) Quit() error

Quit quits the program and releases the terminal.

func (*TestModel) Send

func (tm *TestModel) Send(m tea.Msg)

Send sends messages to the underlying program.

func (*TestModel) Type

func (tm *TestModel) Type(s string)

Type types the given text into the given program.

func (*TestModel) WaitFinished

func (tm *TestModel) WaitFinished(tb testing.TB, opts ...FinalOpt)

WaitFinished waits for the app to finish. This method only returns once the program has finished running or when it times out.

type TestModelOptions

type TestModelOptions struct {
	// contains filtered or unexported fields
}

TestModelOptions defines all options available to the test function.

type TestOption

type TestOption func(opts *TestModelOptions)

TestOption is a functional option.

func WithInitialTermSize

func WithInitialTermSize(x, y int) TestOption

WithInitialTermSize ...

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.

type WaitingForContext

type WaitingForContext struct {
	Duration      time.Duration
	CheckInterval time.Duration
}

WaitingForContext is the context for a WaitFor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL