expect

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 3 Imported by: 3

README

expect

Expect is used to used to invoke matchers and give a helpful error message. Expect helps a test read well and minimize overhead and scaffolding.

func TestSomething(t *testing.T) {
    x := "foo"
    Expect(t, x).To(Equal("bar"))
}

The previous example will fail and pass the error from the matcher Equal to t.Fatal.

func TestSomething(t *testing.T) {
    x := "foo"
    Expect(t, x).To(StartsWith("foobar"))
}

This example will pass.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffMatcher

type DiffMatcher interface {
	UseDiffer(matchers.Differ)
}

Differ is a type of matcher that will need to diff its expected and actual values.

type Expectation

type Expectation func(actual any) *To

Expectation is provided to make it clear what the expect function does.

func New

func New(t T, opts ...Opt) Expectation

New creates a new Expectation

type Opt

type Opt func(To) To

Opt is an option that can be passed to New to modify Expectations.

func WithDiffer

func WithDiffer(d matchers.Differ) Opt

WithDiffer stores the diff.Differ to be used when displaying diffs between actual and expected values.

type T

type T interface {
	Fatalf(format string, args ...any)
}

T is a type that we can perform assertions with.

type THelper

type THelper interface {
	Helper()
}

THelper has the method that tells the testing framework that it can declare itself a test helper.

type To

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

To is a type that stores actual values prior to running them through matchers.

func Expect

func Expect(t T, actual any) *To

Expect performs New(t)(actual).

func (*To) To

func (t *To) To(matcher matchers.Matcher)

To takes a matcher and passes it the actual value, failing t's T value if the matcher returns an error.

type ToMatcher

type ToMatcher interface {
	Match(actual any) (resultValue any, err error)
}

ToMatcher is a type that can be passed to (*To).To().

Jump to

Keyboard shortcuts

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