Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

doc.gno

1.07 Kb · 40 lines
 1// Package expect provides testing support for packages and realms.
 2//
 3// Values can be asserted using the `Value()` function, for example:
 4//
 5//	func TestFoo(t *testing.T) {
 6//	  got := 42
 7//	  expect.Value(t, got).ToEqual(42)
 8//	  expect.Value(t, got).Not().ToEqual(0)
 9//
10//	  expect.Value(t, "foo").ToEqual("foo")
11//	  expect.Value(t, 42).AsInt().Not().ToBeGreaterThan(50)
12//	  expect.Value(t, "TRUE").AsBoolean().ToBeTruthy()
13//	}
14//
15// Functions can also be used to assert returned values, errors or panics.
16//
17// Package supports four type of functions:
18//
19//   - func()
20//   - func() any
21//   - func() error
22//   - func() (any, error)
23//
24// Functions can be asserted using the `Func()` function, for example:
25//
26//	func TestFoo(t *testing.T) {
27//	  expect.Func(t, func() {
28//	    panic("Boom!")
29//	  }).ToPanic().WithMessage("Boom!")
30//
31//	  wantErr := errors.New("Boom!")
32//	  expect.Func(t, func() error {
33//	    return wantErr
34//	  }).ToFail().WithMessage("Boom!")
35//
36//	  expect.Func(t, func() error {
37//	    return wantErr
38//	  }).ToFail().WithError(wantErr)
39//	}
40package expect