New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yield object instead of string in cy.wait when request content-type is valid JSON Mime type (not only application/json) #14763
Comments
Sounds like 'cypress/packages/driver/src/cy/net-stubbing/events/utils.ts' just needs to be updated to detect more valid JSON MIME types. I don't think we should proactively JSON.parse all incoming request and response bodies, sounds like it could do more harm than good. For example, if you have an endpoint that returns plain text, the type of the response could be |
Good points. I did some testing and A brief search on iana turned up a few likely JSON-compatible media types:
Most seem to follow the same pattern:
Perhaps the check could be expanded to: return contentType && /^application\/.*json/i.test(contentType) |
@aethr Sounds good. If it gets done by March we can squeeze it into the 7.0.0 release. |
Internal Jira issue: TR-681 |
The code for this is done in cypress-io/cypress#15129, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Possibly a duplicate or related to #14273.
Our back-end services use JSON:API spec (https://jsonapi.org/) which recommends the media type application/vnd.api+json. They deliver valid JSON in the response body, which should be converted to an object by
cy.wait
to allow for deep assertions.Current behavior
If request is intercepted with
cy.intercept()
, thency.wait()
yields a string for the response body (related issue: #14273.)From this comment: #14273 (comment), I believe this is due to the check in
cypress/packages/driver/src/cy/net-stubbing/events/utils.ts
Lines 4 to 20 in 6ee7a9c
Due to our back-end sending
content-type: application/vnd.api+json
this check fails, and so the response body is not converted usingJSON.parse
.Desired behavior
I believe that if the response to a request is valid JSON, it should be converted to a JS object regardless of the headers. This approach is taken elsewhere in Cypress, ie:
cypress/packages/server/lib/controllers/xhrs.js
Lines 9 to 23 in dae76a8
Effectively if
JSON.parse(text)
succeeds without throwing, we can assume thattext
is valid JSON and return the resulting parsed object.Test code to reproduce
Versions
6.3.0
The text was updated successfully, but these errors were encountered: