MCPcopy
hub / github.com/gin-gonic/gin / TestContextRenderJSON

Function TestContextRenderJSON

context_test.go:1061–1070  ·  context_test.go::TestContextRenderJSON

Tests that the response is serialized as JSON and Content-Type is set to application/json and special HTML characters are escaped

(t *testing.T)

Source from the content-addressed store, hash-verified

1059// and Content-Type is set to application/json
1060// and special HTML characters are escaped
1061func TestContextRenderJSON(t *testing.T) {
1062 w := httptest.NewRecorder()
1063 c, _ := CreateTestContext(w)
1064
1065 c.JSON(http.StatusCreated, H{"foo": "bar", "html": "<b>"})
1066
1067 assert.Equal(t, http.StatusCreated, w.Code)
1068 assert.JSONEq(t, "{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}", w.Body.String())
1069 assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
1070}
1071
1072// Tests that the response is serialized as JSONP
1073// and Content-Type is set to application/javascript

Callers

nothing calls this directly

Calls 5

CreateTestContextFunction · 0.85
StringMethod · 0.65
JSONMethod · 0.45
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected