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)
| 1059 | // and Content-Type is set to application/json |
| 1060 | // and special HTML characters are escaped |
| 1061 | func 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 |
nothing calls this directly
no test coverage detected