MCPcopy Create free account
hub / github.com/gavv/httpexpect / JSONP

Method JSONP

response.go:946–967  ·  view source on GitHub ↗

JSONP returns a new Value instance with JSONP decoded from response body. JSONP succeeds if response contains "application/javascript" Content-Type header with empty or "utf-8" charset and response body of the following form: callback( ); or: callback( ) Whitespaces are

(callback string, options ...ContentOpts)

Source from the content-addressed store, hash-verified

944// MediaType: "application/javascript",
945// }).Array().ConsistsOf("foo", "bar")
946func (r *Response) JSONP(callback string, options ...ContentOpts) *Value {
947 opChain := r.chain.enter("JSONP()")
948 defer opChain.leave()
949
950 if opChain.failed() {
951 return newValue(opChain, nil)
952 }
953
954 if len(options) > 1 {
955 opChain.fail(AssertionFailure{
956 Type: AssertUsage,
957 Errors: []error{
958 errors.New("unexpected multiple options arguments"),
959 },
960 })
961 return newValue(opChain, nil)
962 }
963
964 value := r.getJSONP(opChain, "JSONP()", callback, options...)
965
966 return newValue(opChain, value)
967}
968
969var (
970 jsonp = regexp.MustCompile(`^\s*([^\s(]+)\s*\((.*)\)\s*;*\s*$`)

Callers 6

TestResponse_JSONPFunction · 0.95
TestResponse_ContentOptsFunction · 0.95
TestResponse_ReaderFunction · 0.95
TestResponse_UsageFunction · 0.95
TestResponse_FailedChainFunction · 0.80
TestResponse_NoContentFunction · 0.80

Calls 6

getJSONPMethod · 0.95
newValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 6

TestResponse_JSONPFunction · 0.76
TestResponse_ContentOptsFunction · 0.76
TestResponse_ReaderFunction · 0.76
TestResponse_UsageFunction · 0.76
TestResponse_FailedChainFunction · 0.64
TestResponse_NoContentFunction · 0.64