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

Method Text

response.go:761–789  ·  view source on GitHub ↗

Text returns a new String instance with response body. Text succeeds if response contains "text/plain" Content-Type header with empty or "utf-8" charset. Example: resp := NewResponse(t, response) resp.Text().IsEqual("hello, world!") resp.Text(ContentOpts{ MediaType: "text/plain", }).IsEqua

(options ...ContentOpts)

Source from the content-addressed store, hash-verified

759// MediaType: "text/plain",
760// }).IsEqual("hello, world!")
761func (r *Response) Text(options ...ContentOpts) *String {
762 opChain := r.chain.enter("Text()")
763 defer opChain.leave()
764
765 if opChain.failed() {
766 return newString(opChain, "")
767 }
768
769 if len(options) > 1 {
770 opChain.fail(AssertionFailure{
771 Type: AssertUsage,
772 Errors: []error{
773 errors.New("unexpected multiple options arguments"),
774 },
775 })
776 return newString(opChain, "")
777 }
778
779 if !r.checkContentOptions(opChain, options, "text/plain") {
780 return newString(opChain, "")
781 }
782
783 content, ok := r.getContent(opChain, "Text()")
784 if !ok {
785 return newString(opChain, "")
786 }
787
788 return newString(opChain, string(content))
789}
790
791// Form returns a new Object instance with form decoded from response body.
792//

Callers 13

TestResponse_TextFunction · 0.95
TestResponse_ContentOptsFunction · 0.95
TestResponse_ReaderFunction · 0.95
TestResponse_UsageFunction · 0.95
TestResponse_FailedChainFunction · 0.80
TestResponse_NoContentFunction · 0.80
TestFastHTTPFunction · 0.80
TestGaeFunction · 0.80
TestE2EFs_FastBinderFunction · 0.80
testCookieHandlerFunction · 0.80
TestE2EPrinter_SmokeFunction · 0.80
TestE2EPrinter_SingleFunction · 0.80

Calls 7

checkContentOptionsMethod · 0.95
getContentMethod · 0.95
newStringFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 13

TestResponse_TextFunction · 0.76
TestResponse_ContentOptsFunction · 0.76
TestResponse_ReaderFunction · 0.76
TestResponse_UsageFunction · 0.76
TestResponse_FailedChainFunction · 0.64
TestResponse_NoContentFunction · 0.64
TestFastHTTPFunction · 0.64
TestGaeFunction · 0.64
TestE2EFs_FastBinderFunction · 0.64
testCookieHandlerFunction · 0.64
TestE2EPrinter_SmokeFunction · 0.64
TestE2EPrinter_SingleFunction · 0.64