| 296 | } |
| 297 | |
| 298 | func TestContextJSONP(t *testing.T) { |
| 299 | e := New() |
| 300 | rec := httptest.NewRecorder() |
| 301 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 302 | c := e.NewContext(req, rec) |
| 303 | |
| 304 | callback := "callback" |
| 305 | err := c.JSONP(http.StatusOK, callback, user{ID: 1, Name: "Jon Snow"}) |
| 306 | if assert.NoError(t, err) { |
| 307 | assert.Equal(t, http.StatusOK, rec.Code) |
| 308 | assert.Equal(t, MIMEApplicationJavaScriptCharsetUTF8, rec.Header().Get(HeaderContentType)) |
| 309 | assert.Equal(t, callback+"("+userJSON+"\n);", rec.Body.String()) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | func TestContextJSONBlob(t *testing.T) { |
| 314 | e := New() |