Skip to content

maelvls/snapgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

mock.EXPECT().
    SomeFunction(snap.InlineSnapshot(deeplyNestedStruct))

Running with .Update() will update the snapshots and the deeplyNestedStruct will get filled with the 'got' value:

snap.InlineSnapshot(nil).Update().Matches(&struct{data string}{"foo"})

will become

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)

About

Jest Snapshots for Gomock proof of concept

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages