Documentation ¶
Index ¶
- func Dir(dir string) func(*Config)
- func Ext(ext string) func(*Config)
- func Filename(name string) func(*Config)
- func MatchJSON(t TestingT, input any, matchers ...matchers.JsonMatcher)
- func MatchSnapshot(t TestingT, values ...any)
- func MatchStandaloneSnapshot(t TestingT, value any)
- func Skip(t TestingT, args ...any)
- func SkipNow(t TestingT)
- func Skipf(t TestingT, format string, args ...any)
- func SortProperties() func(*Config)
- func Update(u bool) func(*Config)
- type Config
- func (c *Config) Extension() string
- func (c *Config) Filename() string
- func (c *Config) MatchJSON(t TestingT, input any, matchers ...matchers.JsonMatcher)
- func (c *Config) MatchSnapshot(t TestingT, values ...any)
- func (c *Config) MatchStandaloneSnapshot(t TestingT, value any)
- func (c *Config) SnapsDir() string
- func (c *Config) SortProperties() bool
- func (c *Config) Update() *bool
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dir ¶
Dir Specify folder name where snapshots are stored
default: __snapshots__
Accepts absolute paths
func Ext ¶
Ext Specify file name extension
default: .snap
Note: even if you specify a different extension the file still contain .snap e.g. if you specify .txt the file will be .snap.txt
func Filename ¶
Filename Specify folder name where snapshots are stored
default: __snapshots__
this doesn't change the file extension see `snap.Ext`
func MatchJSON ¶
func MatchJSON(t TestingT, input any, matchers ...matchers.JsonMatcher)
MatchJSON verifies the input matches the most recent snap file. Input can be a valid json string or []byte or whatever value can be passed successfully on `json.Marshal`.
MatchJSON(t, `{"user":"mock-user","age":10,"email":"mock@email.com"}`) MatchJSON(t, []byte(`{"user":"mock-user","age":10,"email":"mock@email.com"}`)) MatchJSON(t, User{10, "mock-email"})
MatchJSON also supports passing matchers as a third argument. Those matchers can act either as validators or placeholders for data that might change on each invocation e.g. dates.
MatchJSON(t, User{created: time.Now(), email: "mock-email"}, match.Any("created"))
func MatchSnapshot ¶
MatchSnapshot verifies the values match the most recent snap file You can pass multiple values
MatchSnapshot(t, 10, "hello world")
or call MatchSnapshot multiples times inside a test
MatchSnapshot(t, 10) MatchSnapshot(t, "hello world")
The difference is the latter will create multiple entries.
func MatchStandaloneSnapshot ¶
MatchStandaloneSnapshot verifies the value matches the most recent snap file
MatchStandaloneSnapshot(t, "Hello World")
MatchStandaloneSnapshot creates one snapshot file per call.
You can call MatchStandaloneSnapshot multiple times inside a test. It will create multiple snapshot files at `__snapshots__` folder by default.
func Skip ¶
Skip Wrapper of testing.Skip
Keeps track which snapshots are getting skipped and not marked as obsolete.
func SkipNow ¶
func SkipNow(t TestingT)
SkipNow Wrapper of testing.SkipNow
Keeps track which snapshots are getting skipped and not marked as obsolete.
func Skipf ¶
Skipf Wrapper of testing.Skipf
Keeps track which snapshots are getting skipped and not marked as obsolete.
func SortProperties ¶ added in v0.0.10
func SortProperties() func(*Config)
SortProperties sort properties in snapshots
default: false
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func WithConfig ¶
WithConfig Create snaps with configuration
snaps.WithConfig(snaps.Filename("my_test")).MatchSnapshot(t, "hello world")
func (*Config) MatchJSON ¶
func (c *Config) MatchJSON(t TestingT, input any, matchers ...matchers.JsonMatcher)
MatchJSON verifies the input matches the most recent snap file. Input can be a valid json string or []byte or whatever value can be passed successfully on `json.Marshal`.
MatchJSON(t, `{"user":"mock-user","age":10,"email":"mock@email.com"}`) MatchJSON(t, []byte(`{"user":"mock-user","age":10,"email":"mock@email.com"}`)) MatchJSON(t, User{10, "mock-email"})
MatchJSON also supports passing matchers as a third argument. Those matchers can act either as validators or placeholders for data that might change on each invocation e.g. dates.
MatchJSON(t, User{created: time.Now(), email: "mock-email"}, match.Any("created"))
func (*Config) MatchSnapshot ¶
MatchSnapshot verifies the values match the most recent snap file You can pass multiple values
MatchSnapshot(t, 10, "hello world")
or call MatchSnapshot multiples times inside a test
MatchSnapshot(t, 10) MatchSnapshot(t, "hello world")
The difference is the latter will create multiple entries.
func (*Config) MatchStandaloneSnapshot ¶
MatchStandaloneSnapshot verifies the value matches the most recent snap file
MatchStandaloneSnapshot(t, "Hello World")
MatchStandaloneSnapshot creates one snapshot file per call.
You can call MatchStandaloneSnapshot multiple times inside a test. It will create multiple snapshot files at `__snapshots__` folder by default.