github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/render/json_test.go (about)

     1  package render
     2  
     3  import (
     4  	"bytes"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func Test_JSON(t *testing.T) {
    12  	r := require.New(t)
    13  
    14  	e := NewEngine()
    15  
    16  	re := e.JSON(Data{"hello": "world"})
    17  	r.Equal("application/json; charset=utf-8", re.ContentType())
    18  
    19  	bb := &bytes.Buffer{}
    20  
    21  	r.NoError(re.Render(bb, nil))
    22  	r.Equal(`{"hello":"world"}`, strings.TrimSpace(bb.String()))
    23  }