Documentation
¶
Overview ¶
Package snap contains snapshot test functionality.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunBubbleTeaSnapshots ¶
func RunBubbleTeaSnapshots( snapshotSuite *SnapshotSuite, m tea.Model, verify bool, seriesID string, equal VerifyFunc, )
RunBubbleTeaSnapshots runs snapshots for bubbletea TUIs.
func ToSafeFilename ¶
ToSafeFilename replaces all non-safe characters with underscore.
Types ¶
type Snapshot ¶
type Snapshot struct {
// Name of the test that's also the last part of the snapshot file's filepath.
Name string
// contains filtered or unexported fields
}
Snapshot represents a single test with a snapshot file.
func (*Snapshot) Run ¶
Run the snapshot process according to parameters set in snap.SnapshotSuite.NewSnapshot. Error is returned when something unexpected fails, not when the test itself fails. Determining whether any given test fails is left for "equal" function defined in snap.SnapshotSuite.NewSnapshot.
type SnapshotSuite ¶
type SnapshotSuite struct {
// contains filtered or unexported fields
}
A SnapshotSuite is a suite of snapshot tests with a shared directory for the snapshot files. It is made of [snap.Snapshot]s.
func NewSnapshotSuite ¶
func NewSnapshotSuite(rootDir string) *SnapshotSuite
NewSnapshotSuite creates a snap.SnapshotSuite with a root directory. Usually it's under "testdata".
func (*SnapshotSuite) NewSnapshot ¶
func (v *SnapshotSuite) NewSnapshot(name string, verify bool, equal VerifyFunc) *Snapshot
NewSnapshot creates a snapshot. Name is snap.Snapshot.Name and with [snap.SnapshotSuite.rootDir], becomes the full filepath of the snapshot file. When verify is false, snapshots are written, and tests won't fail. That's how you initialize or update snapshots. When verify is true and snapshot file doesn't exist or it's empty, content produced by the tested code is written. And finally, when verify is true and the snapshot file exists, equal function is used to assert equality.
type VerifyFunc ¶
type VerifyFunc func(expected, actual, message string)
VerifyFunc is used to assert that snapshot matches to the string that code produced. This is your standard "assertEqual" function in any unit test library.