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
intercept() sometimes parses request or response body as ArrayBuffer #17055
Comments
I think this may be addressed in this issue, which will be fixed in our next release. #16292 |
Awesome, thanks. I’ll make sure to close the issue once the release is out 👍 |
after upgrade cypress to latest 7.6.0 i'm having same issue like #16292 with test example at this message |
Same goes for me. I updated the example with latest version, you can observe the issue still happening. |
I also found this issue in my project too. (Cypress 7.5.0) |
I'm experiencing the same issue with Hungarian strings, using Cypress 7.7.0. Not just the special characters, but the structure of the JSON object and the distance between the special characters seems to be important. Test code to reproduce: const data9as = {
a: [
{
a: "üaaaaaaaaaé", // 9 a-s between
b: 1,
},
],
};
const data8as = {
a: [
{
a: "üaaaaaaaaé", // 8 a-s between
b: 1,
},
],
};
it("cy.intercept hungarian issue test", () => {
cy.intercept("https://example.com/test", {
body: { result: "ok" },
}).as("testRequest");
cy.window().then(() => {
const xhr = new XMLHttpRequest();
xhr.open("PUT", "https://example.com/test");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(data9as));
});
cy.wait("@testRequest")
.its("request")
.then((req) => {
expect(req.body).to.not.be.an("ArrayBuffer"); // ❗️ fails
expect(req.body).to.be.an("object"); // ❗️ fails
});
cy.window().then(() => {
const xhr = new XMLHttpRequest();
xhr.open("PUT", "https://example.com/test");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(data8as));
});
cy.wait("@testRequest")
.its("request")
.then((req) => {
expect(req.body).to.not.be.an("ArrayBuffer"); // ✅ passes
expect(req.body).to.be.an("object"); // ✅ passes
});
}); |
same issue with Russian letters |
Similar issue with tilde latin letters (
I've also found #16292 which seems fixed, but may not. |
I've found that this also happens with Japanese characters in |
@jennifer-shehane I wanted to help a bit and created reproducible failed tests → https://github.com/lorenzogrv/cy-intercept-latin-error An excerpt const URL = 'https://example.com/test'
function request (body) {
// performs an XMLHttpRequest to URL
}
function dryAssert (interception) {
const { request: req } = interception
expect(req.body).to.not.be.an('ArrayBuffer')
expect(req.body).to.be.an('object')
}
describe('cy.intercept latin tilde ArrayBuffer issue', () => {
beforeEach(() => {
cy.intercept(URL, { body: { result: 'ok' } }).as('interception')
})
describe('Cases working as of 8.x', () => {
it('should work single "letter with tilde"', () => { // ✅
request({ key: 'á' })
cy.wait('@interception').then(dryAssert)
})
it('should work with fiveteen "letters with tilde"', () => { // ✅
request({ key: 'áéíóúáéíóúáéíóú' })
cy.wait('@interception').then(dryAssert)
})
it('should work with letters with tilde" within key', () => { // ✅
request({ 'tíldéd Kéy': null })
cy.wait('@interception').then(dryAssert)
})
})
describe('Cases not working as of 8.x', () => {
it('should work with mixed tilded and non-tilted letters', () => { // ❗️
request({ key: 'válúéwíthsómánytíldés' })
cy.wait('@interception').then(dryAssert)
})
it('should work with letters with tilde" within key and value', () => { // ❗️
request({ 'tíldéd Kéy': 'áéíóúáéíóúáéíóú' })
cy.wait('@interception').then(dryAssert)
})
})
}) After research I can conclude the JSON structure does not need to be complicated to reproduce the bug |
I have tested the reploducible I shared above with cypress |
Mine also passes in 8.2.0. Thank you! |
Issue we had with an ArrayBuffer response seems to have gone in 8.2 as well. |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
Current behavior
Some intercepts don’t parse request or response body well, instead of JSON, it is parsed as ArrayBuffer.
Test code to reproduce
You can find the whole code example here. I was unable to pin down what kind of response or request body caused this. I tried to create a minimalistic example but I ended up just copying the whole payload from the app I’m testing.
Versions
Problem appears from v7 and higher.
.intercept()
actually behaves well on 6.x versions.The text was updated successfully, but these errors were encountered: