https://github.com/maelvls/snapgo
Jest Snapshots for Gomock proof of concept
https://github.com/maelvls/snapgo
go gomock jest-inline-snapshots
Last synced: over 1 year ago
JSON representation
Jest Snapshots for Gomock proof of concept
- Host: GitHub
- URL: https://github.com/maelvls/snapgo
- Owner: maelvls
- Created: 2019-12-07T22:38:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-08T08:57:33.000Z (over 6 years ago)
- Last Synced: 2025-01-24T19:43:59.229Z (over 1 year ago)
- Topics: go, gomock, jest-inline-snapshots
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Jest Inline Snapshots for Gomock
**Warning**: this is just a proof-of-concept, please do not use it.
I find Jest inline snapshotting great and wanted to have the same kind of
experience in Go. The issue in Go is that mocking requires a lot of manual
try-and-error when figuring out what input is expected for a mocked call.
The `snap.InlineSnapshot` can be used in gomock's `EXPECT`. Imagine you
have a deeply nested struct:
```go
mock.EXPECT().
SomeFunction(snap.InlineSnapshot(deeplyNestedStruct))
```
Running with `.Update()` will update the snapshots and the
deeplyNestedStruct will get filled with the 'got' value:
```go
snap.InlineSnapshot(nil).Update().Matches(&struct{data string}{"foo"})
```
will become
```go
snap.InlineSnapshot(&struct{data string}{"foo"}).Matches(&struct{data string}{"foo"})
```
(remember to remove `Update()`)
## Caveats
- all the fields, even the nil ones, are shown
- problems with `*string` (and any pointer to constant literals)