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

Function TestContextRenderNoContentJSON

context_test.go:1101–1110  ·  context_test.go::TestContextRenderNoContentJSON

Tests that no JSON is rendered if code is 204

(t *testing.T)

Source from the content-addressed store, hash-verified

1099
1100// Tests that no JSON is rendered if code is 204
1101func TestContextRenderNoContentJSON(t *testing.T) {
1102 w := httptest.NewRecorder()
1103 c, _ := CreateTestContext(w)
1104
1105 c.JSON(http.StatusNoContent, H{"foo": "bar"})
1106
1107 assert.Equal(t, http.StatusNoContent, w.Code)
1108 assert.Empty(t, w.Body.String())
1109 assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
1110}
1111
1112// Tests that the response is serialized as JSON
1113// we change the content-type before

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