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

Function TestContextRenderJSONPWithoutCallback

context_test.go:1088–1098  ·  context_test.go::TestContextRenderJSONPWithoutCallback

Tests that the response is serialized as JSONP and Content-Type is set to application/json

(t *testing.T)

Source from the content-addressed store, hash-verified

1086// Tests that the response is serialized as JSONP
1087// and Content-Type is set to application/json
1088func TestContextRenderJSONPWithoutCallback(t *testing.T) {
1089 w := httptest.NewRecorder()
1090 c, _ := CreateTestContext(w)
1091 c.Request, _ = http.NewRequest(http.MethodGet, "http://example.com", nil)
1092
1093 c.JSONP(http.StatusCreated, H{"foo": "bar"})
1094
1095 assert.Equal(t, http.StatusCreated, w.Code)
1096 assert.JSONEq(t, `{"foo":"bar"}`, w.Body.String())
1097 assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
1098}
1099
1100// Tests that no JSON is rendered if code is 204
1101func TestContextRenderNoContentJSON(t *testing.T) {

Callers

nothing calls this directly

Calls 5

CreateTestContextFunction · 0.85
JSONPMethod · 0.80
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected