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
cy.intercept
request.body is ArrayBuffer for JSON requests with long Cyrillic strings
#16292
Comments
The example you gave would 'sometimes fail' the other assertions because the requests were being made synchronously, so sometimes the 3rd definition had already run by the time the first wait ran. Regardless, the last test below will always reliably fail, as the response is an ArrayBuffer when the response data is it('cy.intercept cyrillyc issue test', () => {
cy.intercept('https://example.com/test', {
body: { result: 'ok' },
}).as('testRequest');
cy.window().then(() => {
let xhr = new XMLHttpRequest();
xhr.open('POST', 'https://example.com/test');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({ name: 'Frausivanovich' }))
})
cy.wait('@testRequest')
.its('request')
.then((req) => {
expect(req.body).to.not.be.an('ArrayBuffer'); // ✅ passes
expect(req.body).to.be.an('object'); // ✅ passes
});
cy.window().then(() => {
let xhr = new XMLHttpRequest();
xhr.open('POST', 'https://example.com/test');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({ name: 'Фраус' }))
})
cy.wait('@testRequest')
.its('request')
.then((req) => {
expect(req.body).to.not.be.an('ArrayBuffer'); // ✅ passes
expect(req.body).to.be.an('object'); // ✅ passes
});
cy.window().then(() => {
let xhr = new XMLHttpRequest();
xhr.open('POST', 'https://example.com/test');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({ name: 'Фраусиванович' }))
})
cy.wait('@testRequest')
.its('request')
.then((req) => {
expect(req.body).to.be.an('ArrayBuffer'); // ✅ passes
expect(req.body).to.be.an('object'); // ❗️ fails
});
}); |
I have the same problem since version 7.0.0, but I couldn't manage to write a test to reproduce this error. In my live tests, I was getting an error but in the isolated test, nothing was reproducible. And now, thanks to @jennifer-shehane , I also managed to reproduce it. |
same issue. cy.intercept('POST', '/graphql', (req) => {
if (req.body.operationName.includes('ListPosts')) {
req.alias = 'gqlListPostsQuery'
}
console.log(req.body)
// any graphql request contains 'mutation' req.body will be arraybuffer
}) cypress 7.3.0 |
It seems that the problem happens with non-ascii characters. I tested with Korean and it fails, too. But interestingly, it passes with less characters, if I change 안녕녕 below with 안녕, it passes. cy.window().then(() => {
let xhr = new XMLHttpRequest()
xhr.open('POST', 'https://example.com/test')
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.send(JSON.stringify({ name: '안녕녕', value: 'sss' }))
})
cy.wait('@testRequest')
.its('request')
.then((req) => {
console.log(req.body)
expect(req.body).to.be.an('ArrayBuffer') // ✅ passes
expect(req.body).to.be.an('object') // ❗️ fails
}) |
The cause of the problem is bevry/istextorbinary#13. |
I submited PR at bevry/istextorbinary#214. It's now awaiting external fix. |
The code for this is done in cypress-io/cypress#16862, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
When sending request with cyrillic strings in json data to url, stubbed by
cy.intercept
,request.body
object is ArrayBuffer, not plain object.Desired behavior
When sending request with cyrillic strings in json data to url, stubbed by
cy.intercept
,request.body
is plain objectTest code to reproduce
Test code to reproduce: https://github.com/KarKarbI4/cypress-cyrillic-intercept-issue/blob/main/cypress/integration/spec.js
Test repo: https://github.com/KarKarbI4/cypress-cyrillic-intercept-issue
Versions
Cypress: cypress@7.1.0, cypress@7.2.0
Browser: Google Chrome 90
OS: MacOS Big Sur 11.2.3
The text was updated successfully, but these errors were encountered: