Provides basic methods for snapshot testing, inspired by jest's snapshots
This package doesn't aim to be anything more than a simple utility to be used in conjunction with
golang's own testing package, or any other testing framework which is also compatible with go test
snapshots are auto-generated and managed by this package:
- Grab the package
go get -u github.com/vancelongwill/snapshot
- Use it in tests
import (
"testing"
"github.com/VanceLongwill/snapshot"
)
type Something struct {
MoreThings []string
}
func TestSomething(t *testing.T) {
something := Something{}
something.MoreThings = []string{"a", "b", "c"}
label := "should be something"
err := snapshot.WithLabel(label).Matches(&something)
// returns an error with a pretty diff if the snapshot doesnt match
if err != nil {
// print the label and the diff
t.Fatalf("Snapshot didn't match.\n - '%s'\n%s",
label,
err.Error())
}
}
- Update failing snapshots
go test ./... -u
Contributions are absolutely welcome!
-
Make sure tests are passing
make test
-
Make sure it passes the linter
make lint
-
Open a pull request