Test_Ctx_JSONP() — fiber Function Reference
Architecture documentation for the Test_Ctx_JSONP() function in ctx_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD c0782441_b996_9bd0_a443_73f0132da503["Test_Ctx_JSONP()"] 7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"] c0782441_b996_9bd0_a443_73f0132da503 -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026 style c0782441_b996_9bd0_a443_73f0132da503 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
ctx_test.go lines 6143–6184
func Test_Ctx_JSONP(t *testing.T) {
t.Parallel()
app := New()
c := app.AcquireCtx(&fasthttp.RequestCtx{})
require.Error(t, c.JSONP(complex(1, 1)))
err := c.JSONP(Map{
"Name": "Grame",
"Age": 20,
})
require.NoError(t, err)
require.Equal(t, `callback({"Age":20,"Name":"Grame"});`, string(c.Response().Body()))
require.Equal(t, "text/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type")))
err = c.Res().JSONP(Map{
"Name": "Grame",
"Age": 20,
}, "john")
require.NoError(t, err)
require.Equal(t, `john({"Age":20,"Name":"Grame"});`, string(c.Response().Body()))
require.Equal(t, "text/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type")))
t.Run("custom json encoder", func(t *testing.T) {
t.Parallel()
app := New(Config{
JSONEncoder: func(_ any) ([]byte, error) {
return []byte(`["custom","json"]`), nil
},
})
c := app.AcquireCtx(&fasthttp.RequestCtx{})
err := c.JSONP(Map{ // map has no order
"Name": "Grame",
"Age": 20,
})
require.NoError(t, err)
require.Equal(t, `callback(["custom","json"]);`, string(c.Response().Body()))
require.Equal(t, "text/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type")))
})
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Ctx_JSONP() do?
Test_Ctx_JSONP() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_JSONP() defined?
Test_Ctx_JSONP() is defined in ctx_test.go at line 6143.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free