You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this is because request.coffee only returns JSON if content-type exactly matches application/json, based on these lines in the develop branch:
contentTypeIsJson: (response) ->## TODO: use https://github.com/jshttp/type-is for thisresponse?.headers?["content-type"]?.includes("application/json")
Those lines include a TODO which suggests using type-is to improve on the potential JSON content-type pattern-matching.
Desired behavior:
Cypress XHR responses with a content-type of application/vnd.api+json also have their bodies parsed as JSON. Happy to write a PR to use type-is to handle application\/[\S]+?\+?json$ if no one objects.
Steps to reproduce: (app code and test code)
This spec will write a fixture file without the bodies of the responses, they will all be undefined:
describe('Cypress does not parse JSON API',()=>{// We declare an empty array to gather XHR responsesconstxhrData=[];after(()=>{// In record mode, save gathered XHR data to local JSON fileif(Cypress.env('RECORD')){constpath='./cypress/fixtures/fixture.json';cy.writeFile(path,xhrData);}});it('Works',()=>{cy.server({// Here we handle all requests passing through Cypress' serveronResponse: (response)=>{if(Cypress.env('RECORD')){consturl=response.url;constmethod=response.method;constdata=response.body;// We push a new entry into the xhrData arrayxhrData.push({ url, method, data });}},});// This tells Cypress to hook into any GET requestif(Cypress.env('RECORD')){cy.route({method: 'GET',url: '*',});}if(!Cypress.env('RECORD')){cy.fixture('fixture').then((data)=>{for(leti=0,length=data.length;i<length;i++){cy.route(data[i].method,data[i].url,data[i].data);}});}cy.visit('/');});});
The code for this is done in cypress-io/cypress#5166, but has yet to be released.
We'll update this issue and reference the changelog when it's released.
Current behavior:
If a response comes back with a
content-type
header set toapplication/vnd.api+json
, response.body does not contain JSON:I think this is because
request.coffee
only returns JSON ifcontent-type
exactly matchesapplication/json
, based on these lines in the develop branch:Those lines include a
TODO
which suggests using type-is to improve on the potential JSONcontent-type
pattern-matching.Desired behavior:
Cypress XHR responses with a content-type of
application/vnd.api+json
also have their bodies parsed as JSON. Happy to write a PR to usetype-is
to handleapplication\/[\S]+?\+?json$
if no one objects.Steps to reproduce: (app code and test code)
This spec will write a fixture file without the bodies of the responses, they will all be
undefined
:Versions
The text was updated successfully, but these errors were encountered: