Jest-like snapshot built on top of gock.
It allows you to record HTTP request for a test, select the response for each one and replay the snapshot in the test.
Instead of having to manually register all the mocks, they will be discoverd automatically, so you don't need all the gock.New
or gock.Register
calls anymore !
func TestWithHTTP(t *testing.T) {
defer gock.off()
snapshot := gocksnap.MatchSnapshot(t, "name of the scenario")
// put you code here that calls HTTP endpoint
// ...
// call finish to save the snapshot and assert that the test is complete
snapshot.Finish(t)
}
When running the test for the first time, the library will open a web server to select the response for each request:

Select the desired status
and response body
that should be returned for this request, and click Save Snapshot
.
To edit an existing snapshot, you can run your test with the environment variable UPDATE_GOCKSNAP=true
, a new button will appear to reuse the response from the existing snapshot:
