Open fredysiswanto opened 1 year ago
This seems to be the same issue reported on https://github.com/filiphric/cypress-plugin-api/issues/102 I'm facing it as well
A work around if you go into the Cypress-plugin-api node modules there is a support.js file. While this is just something that will work until updated. It does work. You will see
: r
.replace(/&/g, '&')
To fix it do the follwing
: r.toString()
.replace(/&/g, '&')
The workaround will work and hopefully someone can fix it I couldn't find the error in the code just in the minified file.
After much testing and playing with the tool the issue steams from there is a an ArrayBuffer returned. And PrismJs doesn't know how to handle the arraybuffer it only knows how to get the object and parse it into a JSON. Or take a string and make it into a JSON response.
I went through the code and here is what I did to get Prismjs to see the arraybuffer. NOTE: I am not that good at coding so someone who understands this more maybe able to tell what we can do to make it bit better on the response side but at least this is returning response body. Also this only displays the decodeText of the body not the entire response. As you would need to push this into a object that could be turned into a JSON Response. Currently isValidJSON is used while there is a isValidHtml but the valid html is always a arrayBuffer when using the following code: `
cy.fixture(fileName, 'binary')
.then(file => Cypress.Blob.binaryStringToBlob(file, 'text/html'))
.then(blob => {
const httpOptions = {
method: 'POST',
url: `/html`,
headers: {
'content-type': 'multipart/form-data',
},
body: formData,
failOnStatusCode: false,
};
cy.api(httpOptions).then(response => {
const dec = new TextDecoder();
response.body = dec.decode(response.body);
expect(response.status, 'POST Response Status').to.equal(200);
cy.log(response.body)
});
});
` Tried a Simple fix below not elegant
The Result does show in the response
Hi Filip, I'm getting a TypeError when trying to request api with a response non JSON type (Content-Type : text/html; charset=UTF-8). if I try use cy.request my code run normally. Let me know if you need anything else! thank you.
use version 2.1.1