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

Function TestContextRenderJSONP

context_test.go:1074–1084  ·  context_test.go::TestContextRenderJSONP

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

(t *testing.T)

Source from the content-addressed store, hash-verified

1072// Tests that the response is serialized as JSONP
1073// and Content-Type is set to application/javascript
1074func TestContextRenderJSONP(t *testing.T) {
1075 w := httptest.NewRecorder()
1076 c, _ := CreateTestContext(w)
1077 c.Request, _ = http.NewRequest(http.MethodGet, "http://example.com/?callback=x", nil)
1078
1079 c.JSONP(http.StatusCreated, H{"foo": "bar"})
1080
1081 assert.Equal(t, http.StatusCreated, w.Code)
1082 assert.Equal(t, "x({\"foo\":\"bar\"});", w.Body.String())
1083 assert.Equal(t, "application/javascript; charset=utf-8", w.Header().Get("Content-Type"))
1084}
1085
1086// Tests that the response is serialized as JSONP
1087// and Content-Type is set to application/json

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