Skip to content

Commit

Permalink
Do not escape JSON
Browse files Browse the repository at this point in the history
`encoding/json` escapes &, <, and > by default. This is not useful for golden tests and only makes the output harder to read.
  • Loading branch information
mightyguava committed Oct 27, 2020
1 parent f58af5e commit df66e94
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions v2/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ func (g *Goldie) Assert(t *testing.T, name string, actualData []byte) {
// `a-z0-9\-\_` is a good idea).
func (g *Goldie) AssertJson(t *testing.T, name string, actualJsonData interface{}) {
t.Helper()
js, err := json.MarshalIndent(actualJsonData, "", " ")
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetIndent("", " ")
enc.SetEscapeHTML(false)
err := enc.Encode(actualJsonData)

if err != nil {
t.Error(err)
t.FailNow()
}

g.Assert(t, name, normalizeLF(js))
g.Assert(t, name, normalizeLF(buf.Bytes()))
}

// AssertXml compares the actual xml data received with expected data in the
Expand Down

0 comments on commit df66e94

Please sign in to comment.