https://github.com/vancelongwill/snapshot
Snapshot testing for Golang
https://github.com/vancelongwill/snapshot
go golang golang-testing snapshot snapshot-testing testing
Last synced: 4 months ago
JSON representation
Snapshot testing for Golang
- Host: GitHub
- URL: https://github.com/vancelongwill/snapshot
- Owner: VanceLongwill
- License: mit
- Created: 2019-10-12T17:48:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-14T11:51:25.000Z (over 6 years ago)
- Last Synced: 2025-12-17T11:55:28.705Z (7 months ago)
- Topics: go, golang, golang-testing, snapshot, snapshot-testing, testing
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## snapshot
Provides basic methods for snapshot testing, inspired by [jest's snapshots](https://jestjs.io/docs/en/snapshot-testing)
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:
### Getting started
1. Grab the package
```bash
go get -u github.com/vancelongwill/snapshot
```
2. Use it in tests
```golang
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())
}
}
```
3. Update failing snapshots
```bash
go test ./... -u
```
#### Contributing
Contributions are absolutely welcome!
##### Steps
- Make sure tests are passing
```bash
make test
```
- Make sure it passes the linter
```bash
make lint
```
- Open a pull request