Skip to content

millotp/gocksnap

Repository files navigation

gocksnap GitHub release

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 !

Example

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)
}

Preview

When running the test for the first time, the library will open a web server to select the response for each request:

image1

Select the desired status and response body that should be returned for this request, and click Save Snapshot.

Updating a 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:

image2

About

Jest-like snapshot testing for gock

Resources

Stars

Watchers

Forks

Packages

No packages published